Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
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.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script

Reply
 
Old 2 Weeks Ago   #1 (permalink)
PaulM


 
 

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 SpecsSystem Spec
Old 2 Weeks Ago   #2 (permalink)
Pegasus [MVP]


 
 

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")
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.


My System SpecsSystem Spec
Old 2 Weeks Ago   #3 (permalink)
Richard Mueller [MVP]


 
 

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")
>
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 SpecsSystem Spec
Old 2 Weeks Ago   #4 (permalink)
PaulM


 
 

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 SpecsSystem Spec
Reply

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


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46