Using Environment variables in renaming script
Hello.
Does anyone know how to use environment variables, like %ProgramFiles%, within a VBS script when changing a file name?
I have tried with this:
'-------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'%ProgramFiles%\\Testfolder64\\Testfile64.txt'")
For Each objFile in colFiles
errResult = objFile.Rename("%ProgramFiles%\Testfolder64\2Testfile64.txt")
Wscript.Echo errResult
Next
'------------------------------------
But to no avail. Does anyone know whether it's even possible? And, if not, are there any alternatives?
Edit:
Scratch that, I found out how to do it. I use C:\\Progra~1\\, and it works now.
But now a new question arises for me, which may mean that this thread should be moved: is the Progra~1 short name the same in all language versions of Windows?
Edit 2:
Ended up finding this out out myself too xD
This thread can be closed now then...
Does anyone know how to use environment variables, like %ProgramFiles%, within a VBS script when changing a file name?
I have tried with this:
'-------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'%ProgramFiles%\\Testfolder64\\Testfile64.txt'")
For Each objFile in colFiles
errResult = objFile.Rename("%ProgramFiles%\Testfolder64\2Testfile64.txt")
Wscript.Echo errResult
Next
'------------------------------------
But to no avail. Does anyone know whether it's even possible? And, if not, are there any alternatives?
Edit:
Scratch that, I found out how to do it. I use C:\\Progra~1\\, and it works now.
But now a new question arises for me, which may mean that this thread should be moved: is the Progra~1 short name the same in all language versions of Windows?
Edit 2:
Ended up finding this out out myself too xD
This thread can be closed now then...
0 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
itolutions
13 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.