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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WshShell.Run passing string with multiple variables, need help quoting 1

Status
Not open for further replies.
Mar 28, 2012
3
0
0
US
Admin Batch Junkie new to VBScript, trying to evolve

was having issues with this segment in a larger script, so pulled it out to isolate it

getting a "cannot find file specified" on my string "StrDir"

when I Wscript.Echo the string it looks correct

Code:
\\meta05\c$\documents and settings\amis5235

i've tried adding & "\" to the end of the path, and even played around with chr(34)

but I'm hoping someone can point me in the right direction

----------------------
Code:
Set WSHShell = CreateObject("Wscript.Shell")
Set objFS1 = CreateObject("Scripting.FileSystemObject")
server = "meta05"
profile = "amis5235"

'NT
StrDir = "\\" & server & "\c$\documents and settings\" & profile

'WIN7
'StrDir = "\\" & server & "\c$\users\" & profile

If objFS1.FolderExists(StrDir) Then
	'Wscript.echo strdir
	WshShell.Run strdir
	ELSE
	END IF



 
What about this ?
WshShell.Run Chr(34) & strdir & Chr(34)

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PH

I think about the only thing I hadn't tried

was passing Chr(34) inside the method itself
 
Just to get away from hard coding this code snippet will use the environment variables:
Code:
set objWshShell 	= WScript.CreateObject("WScript.Shell" )
strUser 			= objWSHShell.ExpandEnvironmentStrings("%USERNAME%")
strUserProfile 		= objWSHShell.ExpandEnvironmentStrings("%USERPROFILE%")
wscript.echo 	"Username = '" & strUser & "'" & vbCrLf &_
				"User's Profile path = '" & strUserProfile & "'"

JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top