![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Script 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") |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Script "PaulM" <NONO@newsgroup> wrote in message news:OORp6rmXKHA.220@newsgroup Quote: > 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") 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. |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Script "PaulM" <NONO@newsgroup> wrote in message news:OORp6rmXKHA.220@newsgroup Quote: > 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") > 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 -- |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Script Thanks "Richard Mueller [MVP]" <rlmueller-nospam@newsgroup> wrote in message news:OreMP6mXKHA.412@newsgroup Quote: > > "PaulM" <NONO@newsgroup> wrote in message > news:OORp6rmXKHA.220@newsgroup Quote: >> 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 > -- > > |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Logon Script Causing Laptops To Hang - Problems in script? | VB Script | |||
| problem passing args to script 'There is no script engine for file extenstion' | VB Script | |||
| Include another script, keep variables in included script? | PowerShell | |||
| Script file has 'OS Handle' error when run from script | PowerShell | |||
| Can you drag-n-drop a file on top of a PS script to run the script? | PowerShell | |||