Question Locked

Writing a windows script for the net use command

0 helpful
4 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Hi guys,

I am a total newbie when it comes to windows scripts. I really need a script to just mount a shared folder.

So if you guys could help me out with the basics of scripting, that would be awesome. For instance i can type "net use" in the command prompt and get a list of shares im connected to. How do i put that command in a script file? I have tried just writing net use in a text file (which i renamed to a vbs extension) but no luck.
I have tried the full pathname (C:\windows\system32\net.exe use) but still did not work.
What am I doing wrong?

Thanks

Nitin

4 replies

by churdoo

Well if all you're trying to do is map a share, then you don't really need scripting, just a BATCH file (.bat or .cmd). Are you trying to map a drive letter to a given share? If so,
net use x: \\servername\sharename

net use /? will display a help screen giving you more information on the net use command.

Once you get your desired results from the command line, then copy the correct command into a .bat or a .cmd file. I may recommend using the preceeding example:

@net use x: /d >nul
net use x: \\servername\sharename

This will disconnect the drive letter x: (and if x: is not connected, will produce an error which you won't see cuz it's redirected to the nul device, then will connect the drive letter to the proper share)

Hope this helps. If so, send me a Pepe's pizza.

by angeln186

Thanks to both of you. The .bat file worked like a charm and it was exactly what i needed. Something that could run command prompt commands but in a file.

Thanks a lot

by dumphrey

.bat not .vbs, and make sure its really renamed and not .bat.txt (ie show file extensions is enabled).

This discussion is closed to new replies.