Jump to content

Help Convert WMI to AutoIt


Recommended Posts

Ok, I'm not only a noob to AutoIt, but I know nothing about WMI scripts...so, I was wondering if someone out there would be willing to convert the following file to an AutoIt script. ;)

What I am trying to do is remove/uninstall all of the Windows XP Games from several hundred PC's. I found this script on the Internet but I would rather deal with it using AutoIt. :)

Here is the WMI script:

Dim Fso : Set Fso = CreateObject("Scripting.FileSystemObject")

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

sPrograms = WshShell.SpecialFolders("AllUsersPrograms")

If (Fso.FolderExists(sPrograms & "\Games")) Then

' Create file for uninstalling games

Set f = Fso.CreateTextFile("c:\windows\inf\wmdtocm.txt", True)

f.WriteLine("[Components]")

f.WriteLine("freecell=off")

f.WriteLine("hearts=off")

f.WriteLine("minesweeper=off")

f.WriteLine("msnexplr=off")

f.WriteLine("pinball=off")

f.WriteLine("solitaire=off")

f.WriteLine("spider=off")

f.WriteLine("zonegames=off")

f.Close

WshShell.Run "sysocmgr.exe /i:c:\windows\inf\sysoc.inf /u:""c:\windows\inf\wmdtocm.txt"" /q", 1, True

Fso.DeleteFolder(sPrograms & "\Games"), True

End If

Here is what I attempted to convert... ^_^

; Uninstall games from Windows XP

=============================================================================

Dim $Fso

$Fso = ObjCreate("Scripting.FileSystemObject")

$WshShell = ObjCreate("WScript.Shell")

$sPrograms = $WshShell.SpecialFolders("AllUsersPrograms")

If ($Fso.FolderExists($sPrograms & "\Games")) Then

; Create file for uninstalling games

$f = $Fso.CreateTextFile("c:\windows\inf\wmdtocm.txt", True)

$f.WriteLine("[Components]")

$f.WriteLine("freecell=off")

$f.WriteLine("hearts=off")

$f.WriteLine("minesweeper=off")

$f.WriteLine("msnexplr=off")

$f.WriteLine("pinball=off")

$f.WriteLine("solitaire=off")

$f.WriteLine("spider=off")

$f.WriteLine("zonegames=off")

$f.Close <BR>$WshShell.Run ("sysocmgr.exe /i:c:\windows\inf\sysoc.inf /u:", "c:\windows\inf\wmdtocm.txt"" /q", 1, True)

$Fso.DeleteFolder($sPrograms & "\Games", True)

EndIf

Any help on this would be greatly appricated. This would make life so much easier than going to every PC and doing a manual uninstall. :)

Edited by HockeyFan
Link to comment
Share on other sites

No Clue! :)

Where I pulled this info from stated..."So I found a script on the Internet that uses WMI..."

Disregard the WMI since you've got native AutoIt controls and functions to handle each part of the WMI script's tasks:

Dim $folderGames = @ProgramsCommonDir & "\Games"
Dim $fileGamesCleanup = "c:\windows\inf\wmdtocm.txt"
Dim $aComponents[8] = ["freecell", "hearts", "minesweeper", "msnexplr", "pinball", "solitaire", "spider", "zonegames"]
If FileExists($folderGames) Then
    For $i = 0 To UBound($aComponents) - 1
        IniWrite($fileGamesCleanup, "Components", $aComponents[$i], "off")
    Next
EndIf
$params = "/i:c:\windows\inf\sysoc.inf /u:" &Chr(34) &"c:\windows\inf\wmdtocm.txt" &Chr(34) &" " &"/q"

Run(@SystemDir &"\sysocmgr.exe " &$params, @SystemDir)
DirRemove($folderGames,1)

Edit: took out redundant code check from my example

Edited by Monamo

- MoChr(77)& Chr(97)& Chr(100)& Chr(101)& Chr(32)& Chr(121)& Chr(97)& Chr(32)& Chr(108)& Chr(111)& Chr(111)& Chr(107)-------I've told you 100,000 times not to exaggerate!-------Don't make me hit you with my cigarette hand...-------My scripts:Random Episode Selector, Keyboard MouseMover, CopyPath v2.1, SmartRename for XP,Window Tracer[sup]New![/sup]

Link to comment
Share on other sites

Well if you are going to use AutoIt there is no sense in calling the FileSystemObject.

If FileExists(@ProgramsCommonDir & "\Games") Then
    ; Create file for uninstalling games
    $f = FileOpen("c:\windows\inf\wmdtocm.txt",2)

    FileWriteLine($f, "[Components]")
    FileWriteLine($f, "freecell=off")
    FileWriteLine($f, "hearts=off")
    FileWriteLine($f, "minesweeper=off")
    FileWriteLine($f, "msnexplr=off")
    FileWriteLine($f, "pinball=off")
    FileWriteLine($f, "solitaire=off")
    FileWriteLine($f, "spider=off")
    FileWriteLine($f, "zonegames=off")

    FileClose($f)
    RunWait('sysocmgr.exe /i:c:\windows\inf\sysoc.inf /u: "c:\windows\inf\wmdtocm.txt" /q')

    DirRemove(@ProgramsCommonDir & "\Games", True)
EndIf

EDIT: You may also want to put the @WindowsDir macro in place of c:\windows

RunWait('sysocmgr.exe /i:' & @WindowsDir & '\inf\sysoc.inf /u:"' & @WindowsDir & '\inf\wmdtocm.txt" /q')

Edited by weaponx
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...