Google Answers Logo
View Question
 
Q: A quick VB batch script ( No Answer,   4 Comments )
Question  
Subject: A quick VB batch script
Category: Computers > Programming
Asked by: mg1124-ga
List Price: $40.00
Posted: 14 Nov 2005 10:14 PST
Expires: 14 Dec 2005 10:14 PST
Question ID: 592818
I need a VBScript to carry out the following tasks in order.

1. Execute commands :
C:\Program Files\Altiris\Altiris Agent\aexagentutil.exe /uninstallagents /clean
C:\Program Files\Altiris\Carbon Copy\unsetup.exe -n -q

2. Wait for the above commands to finish then delete folder:
C:\Program Files\Altiris\Altiris Agent

3. Delete the following registry keys if still present: 
HKEY_LOCAL_MACHINE | SOFTWARE | Altiris | Altiris Agent 
HKEY_LOCAL_MACHINE | SOFTWARE | Altiris | eXpress
HKEY_LOCAL_MACHINE | SOFTWARE | Altiris | Scheduler 
HKEY_LOCAL_MACHINE | SOFTWARE | Altiris | APackageStub 
HKEY_LOCAL_MACHINE | SOFTWARE | Classes | All sub items beginning with Altiris 
HKEY_LOCAL_MACHINE | SOFTWARE | Classes | AppID |
{5E038245-CF81-44BE-8018-9A2981B9DC9B}

4. Search in the Windows directory <WINDIR> using the string below and
delete the found files.
*AeX* (* denotes wildcard)
Answer  
There is no answer at this time.

Comments  
Subject: Re: A quick VB batch script by D.R.Kalbande
From: d_r_kalbande-ga on 15 Nov 2005 02:33 PST
 
Dear sir/Madam,
               I am sending you the code which can execute DOS
Commands fired from VB Form.I hope that will help You.
               Thanks.


Steps
1.Take one text box to type the command.(caption :Text1)

2.Take another three command button below the text box and labelled
them as send comand to ftp and send command to command.com and one for
exit.

  Buttons   caption

Command1 : Send command to ftp

Command2 : Send command to command.com

Command3 :exit

3.Code for Coomand1
Private Sub Command1_Click()
Text2.Text = "c:\windows\system32\ftp.exe"
loader
End Sub

4.Code for Command2

Private Sub Command2_Click()
Text2.Text = "c:\windows\system32\command.com"
loader
End Sub  

5.Code for Command3
Private Sub Command4_Click()
End
End Sub


6. Write this function named as loader() in the code window

Private Sub loader()
 Dim CommandWindowName As String
   Dim SendToDos As String
   Clipboard.Clear
   SendToDos = Text1.Text
   Clipboard.SetText SendToDos + Chr$(13)
   Dim lFoundWindow As Long
   Dim manu As Long
   Dim lOK As Long
   Dim lOK1 As Long
   Dim X As Variant
   z = Text2.Text
   Shell z, vbHide
     
lFoundWindow = FindWindow(vbNullString, z)
manu = FindWindow(vbNullString, "Form1")
          
            lOK1 = ShowWindow(lFoundWindow, 9)
            lOK1 = ShowWindow(lFoundWindow, 10)
              SendKeys "% ee", 1
              SendKeys "% ep", 1
              
      lOK = SetForegroundWindow(manu)
        
        lFoundWindow = 0
        lOK = 0
        lOK1 = 0

End Sub

7.Add the following module in the project and paste the following code
in that module.

Public Const SW_HIDE = 0
Public Const SW_SHOWNORMAL = 1
Public Const SW_NORMAL = 1
Public Const SW_SHOWMINIMIZED = 2
Public Const SW_SHOWMAXIMIZED = 3
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOWNOACTIVE = 4
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_SHOWINNOACTIVE = 7
Public Const SW_SHOWNA = 8
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10
Public Const SW_MAX = 10


Public Declare Function FindWindow Lib "user32" Alias "FindWindowA"
(ByVal lpClassName As String, ByVal lpWindowsName As String) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd
As Long) As Long
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long,
ByVal cCmdShow As Long) As Long






Hope yoe like it .

Regards
  Dhananjay R.Kalbande
              M.E.(Info.Tech.)
Subject: Re: A quick VB batch script
From: mg1124-ga on 15 Nov 2005 07:33 PST
 
Sorry I need code that I can run as a VBScript to exectute each of these commands
Subject: Re: A quick VB batch script
From: pianoboy77-ga on 15 Nov 2005 21:06 PST
 
Here you go. Save the script below in a .vbs file, which you can then
run from the command-line by typing:
cscript whateverFileName.vbs

'=============== SCRIPT STARTS HERE ================================

Option Explicit

'-----------------------------------------------------
' 1. Execute commands
'-----------------------------------------------------

Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")

Dim oExec1, oExec2
Set oExec1 = WshShell.Exec("C:\Program Files\Altiris\Altiris Agent" &_
 "\aexagentutil.exe /uninstallagents /clean")

Do While oExec1.Status = 0
     WScript.Sleep 100
Loop

Set oExec2 = WshShell.Exec("C:\Program Files\Altiris" &_
 "\Carbon Copy\unsetup.exe -n -q")

Do While oExec2.Status = 0
     WScript.Sleep 100
Loop

'-----------------------------------------------------
' 2. Delete main directory
'-----------------------------------------------------
Dim commandString1
commandString1 = "%comspec% /c rmdir /s /q ""C:\Program Files\" &_
                  "Altiris\Altiris Agent"" "

'wscript.echo commandString1
WshShell.Run commandString1

'-----------------------------------------------------
' 3a. Delete registry entries
'-----------------------------------------------------
Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

Dim RegHive

'Select registry hive constant from above list.
RegHive = HKEY_LOCAL_MACHINE

'Call helper subroutine to delete registry keys
DelKey RegHive, "Software\Altiris\Altiris Agent"
DelKey RegHive, "Software\Altiris\eXpress"
DelKey RegHive, "Software\Altiris\Scheduler"
DelKey RegHive, "Software\Altiris\APackageStub"
DelKey RegHive, "Software\Altiris\AppID\{5E038245-CF81-44BE-8018-9A2981B9DC9B}"

'-------------------------------------------------------------
'3b. Search for registry entries that match criteria under 
'     Software\Classes key, and delete matches
'-------------------------------------------------------------
Dim strComputer, oReg, strKeyPath, arrSubKeys, subKey
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
 
strKeyPath = "Software\Classes"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
 
If IsArray(arrSubKeys) Then
  'Check if Altiris occurs in string at the very beginning (position is 1-based)
   For Each subKey In arrSubKeys
       If InStr(subKey,"Altiris") = 1 Then
               'Call helper subroutine to delete registry entry
	       DelKey HKEY_LOCAL_MACHINE, strKeyPath + "\" + subKey
       End if
   Next
End If

'-------------------------------------------------------------
'4. Delete *AeX* files in Windows directory
'-------------------------------------------------------------
Dim fso, winFolder, commandString2
Set fso = CreateObject("Scripting.FileSystemObject")

Set winFolder = fso.GetSpecialFolder(0)

commandString2 = "%comspec% /c  C: & cd\ & cd " &_
		  winFolder.Name &_
		  " & del /q *AeX*"
'wscript.echo commandString2

WshShell.Run commandString2

'------------------------------------------------------------------------
' Helper method to recursively delete all subkeys of a key and then
' delete the key itself. This is needed because you get an error if
' you try to delete a key that contains subkeys.
' Copied from: http://www.codecomments.com/archive300-2004-5-198638.html
'------------------------------------------------------------------------
Sub DelKey(RegRoot, sPath)
   Dim sKeys
   Dim SubKeyCount
   Dim objRegistry
   Dim lRC
   Dim lRC2
   Dim Key
   
   Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")
   lRC = objRegistry.EnumKey(RegRoot, sPath, sKeys)

   If IsArray(sKeys) Then
      for each Key in sKeys
         DelKey RegRoot, sPath & "\" & Key
      next
   End If

   lRC2 = objRegistry.DeleteKey(RegRoot, sPath)

   If (lRC2 <> 0) Then
      wscript.echo "Error deleting key " & sPath
   End If
End Sub

'============================= SCRIPT ENDS HERE ===================

Remarks: 
1. The script probably isn't perfect, but hopefully it's something you
can work from.
2. No error handling is done, so if, for example, the uninstaller
program doesn't exist, it will fail trying to execute it and the rest
of the script won't execute.
3. It assumes the place where the user installed the program is 
  "C:\Program Files\...", when the user possibly could have chosen somewhere else.
4. It is very dangerous to delete *AeX* as you are wanting to do. You
should know exactly what files you need to delete and delete them one
by one. What if a critical windows component (or other 3rd party
component) exists called "winaexec.exe" or something? You never know
what might contain a string that you think is unique to your
application files.

Here are some links to helpful pages for implementing the steps:
1,4. http://msdn.microsoft.com/library/en-us/script56/html/wslrfexecmethod.asp
2. http://www.computerperformance.co.uk/ezine/ezine80.htm
3. http://www.codecomments.com/archive300-2004-5-198638.html
Subject: Re: A quick VB batch script
From: mg1124-ga on 17 Nov 2005 04:25 PST
 
Looks good, let me have a play about with it today

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy