From: PaulM on 5 Nov 2009 17:54 Why does this script work: ' Description: Demonstration script that uses the FileSystemObject to delete a file. Local computer ' For Vista Set WSHShell = WScript.CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") objFSO.DeleteFile("F:\Users\TestUser\AppData\Local\test.vbs") And this script does not work: ' Description: Demonstration script that uses the FileSystemObject to delete a file. Local computer ' For Vista Dim Windir Dim Users Dim UserProfile Dim AppData Dim Local Set WSHShell = WScript.CreateObject("WScript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") Windir = WshShell.ExpandEnvironmentStrings("%SystemRoot%") Users = WshShell.ExpandEnvironmentStrings("%Users%") UserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%") AppData = WshShell.ExpandEnvironmentStrings("%AppData%") Local = WshShell.ExpandEnvironmentStrings("%Local%") objFSO.DeleteFile("%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs")
From: Pegasus [MVP] on 5 Nov 2009 18:10 "PaulM" <NONO(a)NONO.COM> wrote in message news:OORp6rmXKHA.220(a)TK2MSFTNGP02.phx.gbl... > Why does this script work: > > ' Description: Demonstration script that uses the FileSystemObject to > delete a file. Local computer > ' For Vista > > Set WSHShell = WScript.CreateObject("WScript.Shell") > Set objFSO = CreateObject("Scripting.FileSystemObject") > > objFSO.DeleteFile("F:\Users\TestUser\AppData\Local\test.vbs") > > > And this script does not work: > > ' Description: Demonstration script that uses the FileSystemObject to > delete a file. Local computer > ' For Vista > > Dim Windir > Dim Users > Dim UserProfile > Dim AppData > Dim Local > > Set WSHShell = WScript.CreateObject("WScript.Shell") > Set objFSO = CreateObject("Scripting.FileSystemObject") > Windir = WshShell.ExpandEnvironmentStrings("%SystemRoot%") > Users = WshShell.ExpandEnvironmentStrings("%Users%") > UserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%") > AppData = WshShell.ExpandEnvironmentStrings("%AppData%") > Local = WshShell.ExpandEnvironmentStrings("%Local%") > > objFSO.DeleteFile("%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs") If you replace the line objFSO.DeleteFile("%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs") with this line wscript.echo "%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs" then you will see immediately why it cannot possibly work. Neither objFSO.DeleteFile nor wscript.echo can resolve environmental variables such as %SystemRoot%. How about something like this? objFSO.DeleteFile(Local & "\test.vbs") I also urge you to open a Command Prompt (click Start / Run / cmd {OK} and type this command: echo %SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local% I took it right from your own code. As you see, it produces nonsense.
From: Richard Mueller [MVP] on 5 Nov 2009 18:20 "PaulM" <NONO(a)NONO.COM> wrote in message news:OORp6rmXKHA.220(a)TK2MSFTNGP02.phx.gbl... > Why does this script work: > > ' Description: Demonstration script that uses the FileSystemObject to > delete a file. Local computer > ' For Vista > > Set WSHShell = WScript.CreateObject("WScript.Shell") > Set objFSO = CreateObject("Scripting.FileSystemObject") > > objFSO.DeleteFile("F:\Users\TestUser\AppData\Local\test.vbs") > > > And this script does not work: > > ' Description: Demonstration script that uses the FileSystemObject to > delete a file. Local computer > ' For Vista > > Dim Windir > Dim Users > Dim UserProfile > Dim AppData > Dim Local > > Set WSHShell = WScript.CreateObject("WScript.Shell") > Set objFSO = CreateObject("Scripting.FileSystemObject") > Windir = WshShell.ExpandEnvironmentStrings("%SystemRoot%") > Users = WshShell.ExpandEnvironmentStrings("%Users%") > UserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%") > AppData = WshShell.ExpandEnvironmentStrings("%AppData%") > Local = WshShell.ExpandEnvironmentStrings("%Local%") > > objFSO.DeleteFile("%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs") > Check out the LocalAppData environment variable. Also, once you retrieve the value of the environment variable and assign it to a variable, use the variable. For example, try: ======== Dim LocalAppData, WshShell, objFSO Set WshShell = CreateObject("Wscript.Shell") Set objFSO = CreateObject("Scripting.FileSystemObject") LocalAppData = WshShell.ExpandEnvironmentStrings("%LocalAppData%") objFSO.DeleteFile(LocalAppData & "\test.vbs") ========= You can troubleshoot with statements similar to: Wscript.Echo LocalAppData & "\test.vbs" -- Richard Mueller MVP Directory Services Hilltop Lab - http://www.rlmueller.net --
From: PaulM on 6 Nov 2009 16:08 Thanks "Richard Mueller [MVP]" <rlmueller-nospam(a)ameritech.nospam.net> wrote in message news:OreMP6mXKHA.412(a)TK2MSFTNGP04.phx.gbl... > > "PaulM" <NONO(a)NONO.COM> wrote in message > news:OORp6rmXKHA.220(a)TK2MSFTNGP02.phx.gbl... >> Why does this script work: >> >> ' Description: Demonstration script that uses the FileSystemObject to >> delete a file. Local computer >> ' For Vista >> >> Set WSHShell = WScript.CreateObject("WScript.Shell") >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> >> objFSO.DeleteFile("F:\Users\TestUser\AppData\Local\test.vbs") >> >> >> And this script does not work: >> >> ' Description: Demonstration script that uses the FileSystemObject to >> delete a file. Local computer >> ' For Vista >> >> Dim Windir >> Dim Users >> Dim UserProfile >> Dim AppData >> Dim Local >> >> Set WSHShell = WScript.CreateObject("WScript.Shell") >> Set objFSO = CreateObject("Scripting.FileSystemObject") >> Windir = WshShell.ExpandEnvironmentStrings("%SystemRoot%") >> Users = WshShell.ExpandEnvironmentStrings("%Users%") >> UserProfile = WshShell.ExpandEnvironmentStrings("%UserProfile%") >> AppData = WshShell.ExpandEnvironmentStrings("%AppData%") >> Local = WshShell.ExpandEnvironmentStrings("%Local%") >> >> objFSO.DeleteFile("%SystemRoot%\%Users%\%UserProfile%\%AppData%\%Local%\test.vbs") >> > > Check out the LocalAppData environment variable. Also, once you retrieve > the value of the environment variable and assign it to a variable, use the > variable. For example, try: > ======== > Dim LocalAppData, WshShell, objFSO > > Set WshShell = CreateObject("Wscript.Shell") > Set objFSO = CreateObject("Scripting.FileSystemObject") > > LocalAppData = WshShell.ExpandEnvironmentStrings("%LocalAppData%") > > objFSO.DeleteFile(LocalAppData & "\test.vbs") > ========= > You can troubleshoot with statements similar to: > > Wscript.Echo LocalAppData & "\test.vbs" > > -- > Richard Mueller > MVP Directory Services > Hilltop Lab - http://www.rlmueller.net > -- > >
|
Pages: 1 Prev: connecting to remote registry not working sometimes Next: IE8 and vbscript |