/build/static/layout/Breadcrumb_cap_w.png

VBSCRIPT don't understand %SYSTEMDRIVE%

Im not good at vbscripting. But i have made a script in Wise which should delete a file at %systemdrive%\Apps\Systemhive
The reason why i wont to use the variable %systemdrive% is so the package can be run no matter what the systemdrive is(c: or g:)

Here is my script
'Delete specified folder and subfolders
'Atention!!! Files or folders will not be saved in Recycle Bin
strFolderPath="m:\apps\Savehive"
Set oShell = CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject" )
If fso.FolderExists(strFolderPath) Then
set demofolder = fso.GetFolder(strFolderPath)
iRC = oShell.Run _
("regsvr32.exe /u /s ""m:\apps\Savehive\1.0.0.25\savehive.dll""", 1, True)
'The True parameter remove the folder forcefully
fso.DeleteFolder strFolderPath, True 'Delete the copied folder
End If

if i change strfolderPAth to = "%systemdrive%\apps\Savehive it dosent work

Can somone tell me why(again im not to familar with vbscripting)

0 Comments   [ + ] Show comments

Answers (5)

Posted by: bkruiser 15 years ago
Orange Belt
0
Set objEnv = objShell.Environment("PROCESS")
objEnv("systemdrive")


strfolderPAth = objEnv("systemdrive") & "\apps\Savehive"
Posted by: Bankeralle 15 years ago
Second Degree Blue Belt
0
Ok i tried your suggestion

The script do look like this now
'Delete specified folder and subfolders
'Atention!!! Files or folders will not be saved in Recycle Bin
Set objEnv = objShell.Environment("PROCESS")
objEnv = ("systemdrive")
strfolderPAth = objEnv("systemdrive") & "\apps\Savehive"
Set fso=CreateObject("Scripting.FileSystemObject" )
If fso.FolderExists(strFolderPath) Then
set demofolder = fso.GetFolder(strFolderPath)

iRC = oShell.Run _
("regsvr32.exe /u ""%systemdrive%\apps\SaveHive\1.0.0.25\savehive.dll""", 1, True)


'The True parameter remove the folder forcefully
fso.DeleteFolder strFolderPath, True 'Delete the copied folder


End If

This fails in line 3 char 1. Again im not to good at this so please if somone could helt me i be grateful
Posted by: funnyproffy2 15 years ago
Senior Yellow Belt
0
ORIGINAL: Bankeralle
Set objEnv = objShell.Environment("PROCESS")

missing line (before this line):
Set objShell = CreateObject("WScript.Shell")
the script needs to know what objShell is, you do that by using the previous line

objEnv = ("systemdrive")

this won't work either, you need to use a line like:
yourvariable = objEnv("SystemDrive")


iRC = oShell.Run _
("regsvr32.exe /u ""%systemdrive%\apps\SaveHive\1.0.0.25\savehive.dll""", 1, True)

You have to change oShell.Run to objShell.Run or you have to change the line I was talking about at the start of this reply - Set objShell = CreateObject(Wscript.Shell)
Posted by: anonymous_9363 15 years ago
Red Belt
0
Your code now doesn't create the objShell object. Try this:'// ALWAYS, ALWAYS, ALWAYS use this and declare your variables before use
Option Explicit

Dim objEnv
Dim strFolderPath
Dim strFile
Dim objFSO
Dim objDemoFolder
Dim intResultCode
Dim intExpectedResultCode
Dim objShell
Dim strCommandLine

intExpectedResultCode = 0 '// I have presumed RegSvr32 returns 0 for success - never tested it! :)

On Error Resume Next

Set objShell = CreateObject("WScript.Shell")
'// ALWAYS trap errors - assume NOTHING!
If Err.Number <> 0 Then
WScript.Quit(False)
End If
Set objEnv = objShell.Environment("PROCESS")
If Err.Number <> 0 Then
WScript.Quit(False)
End If

Set objFSO = CreateObject("Scripting.FileSystemObject" )
If Err.Number <> 0 Then
WScript.Quit(False)
End If

'// Delete specified folder and subfolders
'// Atention!!! Files or folders will not be saved in Recycle Bin
strFolderPath = objEnv("systemdrive") & "\apps\Savehive"

'// Where multiple "calls" to the same object occur (as here with objFSO),
'// it's good practice to use the 'With...End With' construct. That way,
'// the interpreter (let's call it) only needs to reference the memory pointer
'// once. You then refer to the object's methods and properties with just a
'// leading full stop

With objFSO
If .FolderExists(strFolderPath) Then
Set objDemoFolder = .GetFolder(strFolderPath)
If Err.Number <> 0 Then
WScript.Quit(False)
End If


'// NB:
'// You test for the folder's existence but not for that of the file you want to unregister!
'// I'll leave that as an exercise for you.

'// Chr(34) is the ASCII code for quote/speech mark. Using it makes your code easier to read
'// especially where you have to enclose strings in quotes.
'// Also, I like to break down command lines like this (and things like SQL queries) because,
'// again, it makes it easier to read and maintain. Remember: it isn't necessarily YOU who
'// will need to maintain the code!
strFile = "savehive.dll"

strCommandLine = ""
strCommandLine = strCommandLine & "regsvr32 "
strCommandLine = strCommandLine & "/u "
strCommandLine = strCommandLine & Chr(34)
strCommandLine = strCommandLine & strFolderPath
strCommandLine = strCommandLine & "\"
strCommandLine = strCommandLine & strFile
strCommandLine = strCommandLine & Chr(34)

intResultCode = objShell.Run(strCommandLine, 1, True)
If intResultCode <> intExpectedResultCode Then
WScript.Quit(False)
End If

'// The True parameter removes the folder forcefully
.DeleteFolder strFolderPath, True 'Delete the copied folder
If Err.Number <> 0 Then
WScript.Quit(False)
End If

If .FolderExists(strFolderPath) Then
'// Deletion failed
WScript.Quit(False)
End If

End If
End With
Posted by: bkruiser 15 years ago
Orange Belt
0
'Delete specified folder and subfolders
'Atention!!! Files or folders will not be saved in Recycle Bin
strFolderPath="m:\apps\Savehive"
Set oShell = CreateObject("WScript.Shell")
Set fso=CreateObject("Scripting.FileSystemObject" )
Set objEnv = oShell.Environment("PROCESS")
If fso.FolderExists(strFolderPath) Then
set demofolder = fso.GetFolder(strFolderPath)
iRC = oShell.Run _
("regsvr32.exe /u /s ""m:\apps\Savehive\1.0.0.25\savehive.dll""", 1, True)
'The True parameter remove the folder forcefully
fso.DeleteFolder strFolderPath, True 'Delete the copied folder
End If

strfolderPAth = objEnv("systemdrive") & "\apps\Savehive"
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ