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

VBScript to delete a file in profile ....

Status
Not open for further replies.

manowar30

IS-IT--Management
Aug 3, 2012
5
DE
i want to write a script that runs on WinXP 32 Bit and Win7 64 Bit.

It should delete the file "preferences" in the profile


WinXP

"C:\Documents and Settings\Administrator\Local Settings\Application Data\Google\Chrome\User Data\Default\Preferences"

or

Win7

"C:\Users\jeggert\AppData\Local\Google\Chrome\User Data\Default\Preferences"

i ve written a script like this but i do not work:

Dim LocalAppData, WshShell, objFSO

Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

LocalAppData = WshShell.ExpandEnvironmentStrings("%LocalAppData%")

objFSO.DeleteFile(LocalAppData & "\Google\Chrome\User Data\Default\preferences")



Can anybody help me ?


greetings
Joe

 
Your code should work in WIndows 7, but on XP, I believe the environment variable to use is %AppData%
 
What about this ?
LocalAppData = WshShell.ExpandEnvironmentStrings("%tmp%") & "\.."

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
ok, in Win 7 it works fine....

i think i ve the wrong variable für XP %appdata% do not work....

what is the variable for this string:
"C:\Documents and Settings\Administrator\Local Settings\Application Data





@PHV : sorry i dont understand...
 
You don't understand what ?
I provided you a way to get the correct directory either in winXP or win7 ...
Did you even try it ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
You mean like this ?

Sorry i ve just start learning vbs.... can you explain it...




Dim LocalAppData, WshShell, objFSO

Set WshShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")

LocalAppData = WshShell.ExpandEnvironmentStrings("%tmp%")

objFSO.DeleteFile(LocalAppData & "\Google\Chrome\User Data\Default\preferences")



 
i think i ve the wrong variable für XP %appdata% do not work
Yes, sorry... appdata would give you "C:\Documents and Settings\Administrator\Application Data" and you wanted "C:\Documents and Settings\Administrator\[highlight #FCE94F]Local Settings[/highlight]\Application Data"
So that won't work directly.

You mean like this ?
Thats not the exact line PHV had.

PHV: Clever idea, but wouldn't it be:
LocalAppData = WshShell.ExpandEnvironmentStrings("%tmp%") & "\..\Application Data"

I don't have an XP box to test...
 
Yes, you're right guitarzan, that was my idea.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Forgot to mention:
tested with WinXP-SP3 and Win7x64-SP2
 
ok, now i understand ...

i would test it tomorrow...

thx @PHV & guitarzan
 
@PHV : sorry i dont understand...

PHV is suggesting you use the environmental variable [tt]%tmp[/tt] instead of [tt]%LocalAppData%[/tt] because the [tt]%tmp%[/tt] evar points to the user temp directory regardless of OS. From this location you can navigate to your desired folder.

Code:
LocalAppData = WshShell.ExpandEnvironmentStrings("%tmp%")
objFSO.DeleteFile(LocalAppData & "\..\Application Data\Google\Chrome\User Data\Default\preferences")

-Geates

 
>because the %tmp% evar points to the user temp directory regardless of OS

As long as the user has not changed it ...

Here's an alternative using the shell. Create a function:

Code:
[blue]Public Function GetSpecialFolder(SpecialFolder)
    GetSpecialFolder = CreateObject("Shell.application").NameSpace(SpecialFolder).Self.Path
End Function[/blue]

And then you can call it

ssfLOCALAPPDATA = &H1C
MsgBox GetSpecialFolder(ssfLOCALAPPDATA)

A list of the available special folders is available here, which means the function can easily be used to return any of those special folders with little effort.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top