0

How can I launch a program with its own custom appdata folder using a Visual Basic script. I have tried to do this with a batch file:

    @echo off
    set APPDATA=%CD%\appdata
    start program.exe

And it works everywhere except school, as the command prompt is disabled. I have used VBscripts before with success so I thought that might be a good idea.

(BTW, before anyone asks, yes we are allowed to run other programs on the computers and I just need to store the appdata on a USB so it saves my stuff)

Kael Watts-Deuchar
  • 4,213
  • 1
  • 26
  • 50

1 Answers1

0

You can modify a user environment variable in Vbscript like this, but you would have to start your program from within the script, otherwise your environment would be gone when the script closes and even then i'm not sure your program will see the same environment.

Set wshShell = WScript.CreateObject("WScript.Shell")

result=savevar("APPDATA","E:\")
result=getvar("APPDATA")
'=>User environment:E:\'
'*********
Function SaveVar (var,szVar)
  Set wshShellEnv = wshShell.Environment("User")
  WSHShellEnv(var)=szVar
End Function
'*********
Function GetVar (var)
  Set wshShellEnv = wshShell.Environment("User")
  wscript.echo "User environment:" & WSHShellEnv(var)
End Function
peter
  • 41,770
  • 5
  • 64
  • 108