/bundles/itninjaweb/img/Breadcrumb_cap_w.png
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   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
Set objEnv = objShell.Environment("PROCESS")
objEnv("systemdrive")


strfolderPAth = objEnv("systemdrive") & "\apps\Savehive"
Answered 09/23/2009 by: bkruiser
Orange Belt

Please log in to comment
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
Answered 09/24/2009 by: Bankeralle
Second Degree Blue Belt

Please log in to comment
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)
Answered 09/24/2009 by: funnyproffy2
Senior Yellow Belt

Please log in to comment
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
Answered 09/24/2009 by: VBScab
Red Belt

Please log in to comment
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"
Answered 09/24/2009 by: bkruiser
Orange Belt

Please log in to comment