Task to map network drive

Hey everyone,
I’m trying to create a task to map network drives. So far it looks like this:

// Prompt to query drive letter
action parameter query “unidade” with description “Drive letter:” and with default value " "
// Prompt to query foldername
action parameter query “pasta” with description “Sharename:” and with default value " "

delete __createfile
delete run.bat

createfile until end
@ECHO OFF
waithidden cmd /C net.exe use {parameter “unidade” as string}: \\network\{parameter “pasta” as string} /persistent:yes
end

move __createfile run.bat
override wait
hidden=true
completion=job
runas=currentuser
wait run.bat

parameter “returnCode” = "{exit code of action}"
exit {parameter “returnCode”}

The result is an Error Code 1: Incorrect function.

Is it possible to get this via Bigfix action command?

Thanks in advance.

I think, something that you need to take into consideration is that when you run some of this stuff. it normally runs as System and then the scripts dont work as Im assuming you want the drive to be seeing by the end user that us currently logged in.

now, if this the above works, yo can always create the .bat and use the wizard to upload it for you. it will enter all needed commands to execute the .bat

as per Network mapping to all profiles, I think you are better off to resort to AD or group policy

Indeed, it normally runs as System that’s why I’ve tried using the runas=currentuser line, although I’ve never used it this way before and I’m not sure how this effective works.

We are using AD mapping but, for some don’t identified reason, a few computers are not mapping automatically and our support center has to do it manually through remote access.

The idea in here is to map this networks using the current logged on user credentials without bothering the user.

As I said, it is an idea. I ain’t sure if it is realy possible.

We use this on some validation post patching:

delete "BigFixshare.bat"
delete __appendfile
appendfile net share C$=C:\ /GRANT:Everyone,FULL
move __appendfile “BigFixshare.bat"
waithidden “BigFixshare.bat” > “{pathname of parent folder of client}\server_name-Share.txt” 2>&1
parameter “CT”=”{now as string}"
pause while {(now - ((parameter “CT”) as time)) < 5 * minute }
waithidden “BigFixshare.bat” > “{pathname of parent folder of client}\server_name-Share.txt” 2>&1
delete “BigFixshare.bat”

But using net share, as far as I know, is for sharing a folder to make it available to another remote user.
What I’m trying to accomplish is to map a network drive, to assign a drive letter to a specific shared folder of a server on a computer.

Apologies, I misread.

You should be able to use net use instead of net share. The line appendfile is the what is going to be present in the .bat file created.

Can you command line map the drive? if yes, then place that in place of the net share entry.

@baynes74
Thanks for your help but the problem is that with your command lines Bigfix execute as system and not as current user, so the task stops waiting for the login and password to map the drive despite the user is logged and have the correct permissions.

It worked using Software Distribution where I could upload a bat file and set the task to execute as current user. However, the bat file contained the full command line:

net use X: \network\foldername /persistent:yes

The intention is to allow the operator to set the drive letter and the foldername:

net use {parameter “driveletter” as string}: \\network\{parameter “foldername” as string} /persistent:yes

The syntax to get the value of an action parameter query is

{parameter "xxx" of action}

not

{parameter "xxx"}

That said, I’m not convinced that Bigfix is the tool to be doing this - surely, it needs to be run at user logon, not at some random time later?

Actually the parameter replacement works fine. The command line works fine in a bat file through Software Distribution but this way I can set a parameter to the drive letter and folder name.

The idea is allow the operator to set the drive letter (I already have a property to show which letter is free) and the specific server folder to be mapped. This will be used when, for some reason, the correctly server folder isn’t automatically mapped to a specific user through AD policy. Despite we are investigating these problems, users can’t wait to access these files to work.

for the current user…
action parameter query “New Drive” with description “Enter the Drive Letter with a : and fqdn path that you wish to map” with default value “Z: \servername\share”

prefetch RunAsCurrentUser.exe sha1:ee47505ebfb2790b9da8a20ed70e67158e9753d0 size:342528 http://software.bigfix.com/download/bes/util/RunAsCurrentUser-2.0.3.1.exe
utility __Download\RunAsCurrentUser.exe
waithidden __Download\RunAsCurrentUser.exe --w --q cmd.exe /C NET USE {(parameter “New Drive” of action)} /persistent:yes

to Delete…
action parameter query “Mapped Drive” with description “Enter the Drive Letter with a : that you wish to unmap” with default value “Z:”

prefetch RunAsCurrentUser.exe sha1:ee47505ebfb2790b9da8a20ed70e67158e9753d0 size:342528 http://software.bigfix.com/download/bes/util/RunAsCurrentUser-2.0.3.1.exe
utility __Download\RunAsCurrentUser.exe
waithidden __Download\RunAsCurrentUser.exe --w --q cmd.exe /C NET USE {(parameter “Mapped Drive” of action)} /DELETE

2 Likes

Thank you Pete. That worked perfectly!

However, somehow I manage to make it work without the need of downloading the RunAsCurrentUSer file.

Below is the code that worked as well as yours:

action parameter query “letter” with description “Enter the drive letter:” and with default value "Z"
action parameter query “folder” with description “Enter the folder name:” and with default value " "

@ECHO OFF
echo Command: “cmd /C net.exe use {parameter “letter”}: \\server\{parameter “folder”} /persistent:yes”>> "{parameter “logFolder”}{parameter “logFile”}"
set errorlevel=
“cmd /C net.exe use {parameter “letter”}: \\smb.mppr\{parameter “folder”} /persistent:yes”>> “{parameter “logFolder”}{parameter “logFile”}” 2>&1
set SWDExitCode=%errorlevel%
rem //**End Command Marker
exit %SWDExitCode%
end

move __createfile run.bat
waithidden cmd /C copy /Y run.bat “C:\Temp”

override wait
runas=currentuser
completion=job
hidden=true
wait “C:\Temp\run.bat”

//**Begin Closing Marker
// Get the return code of the previous action.
parameter “returnCode” = “{exit code of action}”

exit {parameter “returnCode”}

1 Like