Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie question - using subst with a if then statement 2

Status
Not open for further replies.

Zych

IS-IT--Management
Apr 3, 2003
313
US
Hey Guys and Gals,

I am not very proficient with vbs but I think I can convey what I would like it to do.

I would like to put a statement something like this in a login script:

if exist ("Q:\users\%username%\subdirectory\") Then
subst /d
subst S: Q:\users\%username%\subdirectory
End IF

Subst, as you probably already know, is a DOS command that can assign a drive letter to a subdirectory. How can I run these commands?

Thanks,

Zych
 
You can run command line commands using the Shell Run.

For example:
Code:
Set WSHShell = CreateObject("Wscript.Shell")
WSHSHell.Run ("CMD.EXE /C Start Notepad")

However what you are trying to do is not the most efficient solution. I would map a network drive, assuming you have a share at some higher folder than the user folder it owuld work like this:
Code:
Dim WSHNetwork
Set WSHNetwork = CreateObject("Wscript.Network")
UserString = WSHNetwork.UserName
WSHNetwork.MapNetworkDrive "S:", "Q:\users\"&UserString&"\subdirectory"

I recommend you take a look at my login script FAQ. faq329-5798

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Hey Markdmac,

Thanks for the info. I wish I could use just a map, it would make my life easier. Since it is a local drive I am mapping to it helps keep network traffic down. This is part of a Citrix system. I am also getting some security errors when running it via the network.

I do have one last question however. How can I make this work:

WSHSHell.Run ("subst T: Q:\Documetns and Settings\%username%\winpoint")

When I run the command at a command prompt I get an error due to the spaces in the Documents and Settings section which can be fixed by using quotes. I have tried single quotes in the script, but that does not seem to work. I did try to subst it to the windows directory (in the script) which works fine so I know it will work once I figure that out.

Thanks,

Zych
 
Zych,

The next thing I would try there is double-double quotes. They are how VBS processes a single double quote.

WSHSHell.Run ("subst T: Q:\""Documents and Settings""\%username%\winpoint")

Hopefully that will get you through, good luck!

Eric
 
Either:
WSHSHell.Run "subst T: ""Q:\Documents and Settings\%username%\winpoint"""
Or:
WSHSHell.Run "subst T: " & Chr(34) & "Q:\Documents and Settings\%username%\winpoint" & Chr(34)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
i have a piece of code like this and it works fine in vbs.
Code:
     strPath = "c:\documents and settings\hle832\desktop\"
 
Thanks everybody! The double quotes worked.

WSHSHell.Run ("subst T: ""Q:\Documents and Settings\%username%""")

Thanks again!

- Zych
 
If you create a share on the local resource you CAN do a mapping to it. i do this all the time on my own system to get quicker access to a particular folder.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top