Sign in to follow this  
Followers 0
HockeyFan

Help Convert WMI to AutoIt

7 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



What does this have to do with WMI?

Share this post


Link to post
Share on other sites

What does this have to do with WMI?

No Clue! :)

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

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

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]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Monamo,

Thank you SOOOO MUCH!!!! :)

This is much better than the alternative!

Share this post


Link to post
Share on other sites

weaponx,

Thank you very much as well!! :)

Share this post


Link to post
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
Sign in to follow this  
Followers 0