Jump to content

9 posts in this topic

Posted

I have a script that searches the computer for a specific file and deletes the file called "g2mui.exe". In my case I don't want to delete the file.  Instead there may be multiple versions of this file on the computer and that is okay but I need to grab the path of each "g2mui.exe" and then pass variables from the computer and user to the registry. The problem is I don't know how to do this and I don't know how to do this in order to pass the variables into the registry dynamically via capturing the path of each file.  I am hoping someone can help.  It doesn't need to be a batch script could be powershell, vbs etc..

::Find out what disks are on the system.
for /f "usebackq skip=1 tokens=1" %%a in (`wmic logicaldisk get deviceid`) do (
	::Make sure we only use the fixed disks
	for /f "usebackq tokens=2 delims=:- " %%x in (`fsutil fsinfo drivetype %%a`) do (
		::Is %%a, a fixed disk?
		if "%%x" == "Fixed" (
			cls
			echo - - - - - - - - - - - - - - - - - - - - - - - - - 
			echo Searching drive %%a
			echo - - - - - - - - - - - - - - - - - - - - - - - - - 
			del /s/f/q %%a\"*g2mui.exe*"

		)
	)
)

Example Registry Key:

echo y | reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" /v "C:\Users\%username%\AppData\Local\Citrix\GoToMeeting\1350\g2mui.exe" /t REG_SZ /d "HIGHDPIAWARE"

This path may not be correct on all machines, I need the setting applied to each file found on the machine.:

"C:\Users\%username%\AppData\Local\Citrix\GoToMeeting\1350\g2mui.exe" /t REG_SZ /d "HIGHDPIAWARE"

Some machines have this, thats why I need to grab the path and apply the setting to each file found.

"C:\Program Files\1468\g2mui.exe" /t REG_SZ /d "HIGHDPIAWARE"
"C:\Program Files x86\1068\g2mui.exe" /t REG_SZ /d "HIGHDPIAWARE"

Share this post


Link to post
Share on other sites

Posted

Here is a VBS script that uses WMI to get the path of the file, this searches all local drives for the file so it might take a few minutes to finish. I tested this script by renaming and exe to the one you posted, and placed it into two different drives and folders on my computer, here is what the script returned, d:\updates\g2mui.exe and e:\ea games\g2mui.exe. Renaming the FileName='gsmui1' returned the missing message.
 

Findg2mui.vbs 
 Dim Obj
 Dim Wmi :Set Wmi = GetObject("winmgmts:\\.\root\cimv2")
 Dim Col :Set Col = Wmi.ExecQuery( _
 "Select * from CIM_DataFile Where Extension = 'exe' And FileName='g2mui'")
  If Col.count = 0 Then
  WScript.Echo "Missing :g2mui.exe"
  WScript.Quit
  Else 
   For Each Obj in Col
    Wscript.Echo Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension
   Next 
  End if

Share this post


Link to post
Share on other sites

Posted

If this is what you want done
[attachment=364437:m2guiResult.png]

Then this code will do what you want
 Dim Obj,Reg
 Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Dim Col :Set Col = Wmi.ExecQuery( _
 "Select * from CIM_DataFile Where Extension = 'exe' And FileName='g2mui'")
  If Col.count = 0 Then
  WScript.Echo "Missing :g2mui.exe"
  WScript.Quit
  Else 
   For Each Obj in Col
    Wscript.Echo Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension
    WScript.CreateObject("WScript.Shell").RegWrite _
    "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\HIGHDPIAWARE",_
     Chr(34) & Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension & Chr(34), "REG_SZ"
   Next 
  End if
Rename G2MuiAddReg.vbs.txt to G2MuiAddReg.vbs to make active
[attachment=364439:G2MuiAddReg.vbs.txt]

Share this post


Link to post
Share on other sites

Posted

Thanks I will have to try this out.

Share this post


Link to post
Share on other sites

Posted

This is very close the only issue I am having is it is writing the code backwards in the registry.

Share this post


Link to post
Share on other sites

Posted

Are you trying to do this.
[attachment=364487:RegEntry2.png]

Is so than change this
    WScript.CreateObject("WScript.Shell").RegWrite _
    "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\HIGHDPIAWARE",_
     Chr(34) & Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension & Chr(34), "REG_SZ"
To this
     WScript.CreateObject("WScript.Shell").RegWrite _
    "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" & _
    Replace(Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension,"\","/"),"HIGHDPIAWARE","REG_SZ" 

Share this post


Link to post
Share on other sites

Posted

One last question how can i search only the C: drive?  It is also going through my networked mapped drives.

Share this post


Link to post
Share on other sites

Posted

Are you trying to do this.
attachicon.gifRegEntry2.png

Is so than change this

    WScript.CreateObject("WScript.Shell").RegWrite _
    "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\HIGHDPIAWARE",_
     Chr(34) & Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension & Chr(34), "REG_SZ"
To this
     WScript.CreateObject("WScript.Shell").RegWrite _
    "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" & _
    Replace(Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension,"\","/"),"HIGHDPIAWARE","REG_SZ" 

 

very nice job, but does it possible to replace e:/games/g2mui.exe with e:\games\g2mui.exe?

also does it possible to make it work with any exe file - like in a batch for a whole bunch of exe?

what should I add to make this script write the log file, not to create message boxes on the screen?

Share this post


Link to post
Share on other sites

Posted

replace e:/games/g2mui.exe with e:\games\g2mui.exe?

 
When I was testing the script with \ in the pathway this occur
[attachment=369350:BackSlashChr.png] 
Here is the registry with the 3 ways I could get.
[attachment=369352:AllThreeResults.png] 

also does it possible to make it work with any exe file - like in a batch for a whole bunch of exe?

 
Yes all it would require would
1:\ An Array to hold all the File and their extension
Example 
 Dim App :App = Array("Item.exe","Another.msi","Whatever.cmd")
 
Then you would run that threw another loop with the existing loop
Example 
 Dim App :App = Array("Item.exe","Another.msi","Whatever.cmd")
 Dim a, i
   For Each i in App
'-> Where We Split i to Get The 2 Parts For The Original Script
     a=Split(i,".")
 '-> Process The 2 Varibles In the WMI Query In The Original Script
 Dim Col :Set Col = Wmi.ExecQuery( _
 "Select * from CIM_DataFile Where Extension = 'a(0)' And FileName='a(1)'")
   Next
Here is a VBS script with multiple Items to process
 Dim a, c, i, Obj, Reg, Var, Ts, Tx
 Dim Key :Key = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\"
 Dim Act :Set Act = CreateObject("WScript.Shell")
 Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
 Dim Wmi :Set Wmi = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
 Dim App :App = Array("g2mui.exe","Test.msi", "Test.cmd", "Misc.exe")
'-> Create The Report
 Tx = "InstallReport.txt"
 Set Ts = Fso.CreateTextFile(Tx)
 Ts.WriteLine "Log Report For Auto Search And Install" & vbCrLf & _
              "Start Time : " & Time & vbCrLf & "Start Date : " & Date
  For Each i In App
   a = Split(i,".")
   c = 1 
   Dim Col :Set Col = Wmi.ExecQuery( _
   "Select * from CIM_DataFile Where Extension = '"&a(1)&"' And FileName='"&a(0)&"'")
'-> If Nothing Is Found
   If Col.count = 0 Then
    Ts.WriteLine  "Missing : " & a(0) & "." & a(1) 
   Else 
    For Each Obj in Col
     Var = Obj.Drive & Obj.Path & Obj.FileName & "." & Obj.Extension
     If c = 1 Then
'-> Process Only Once Each Item In The Array Action For File Here
     c = 99
     Ts.WriteLine "Confirm : " & Obj.FileName & "." & Obj.Extension & vbCrLf & Var 
     Else
'-> More Than One File Found
     Ts.WriteLine "No Action : " & Obj.FileName & "." & Obj.Extension & vbCrLf & Var 
     End If 
'-> Makes The Path With \ And The Path Is In "Drive:\Folder\File.Name"
    ' Act.RegWrite Key & "HIGHDPIAWARE",Chr(34) & Var & Chr(34),"REG_SZ"     
'-> Makes Path To File With / Instead Of \ Eg C:/Folder/File.Name
    ' Act.RegWrite Key & Replace(Var,"\","/"),"HIGHDPIAWARE","REG_SZ"  
    Next 
   End If
  Next
'-> Close The Text Stream And Then Open The Report
  Ts.Close 
  Act.Run(Tx),1,False  
Results Of InstallReport.txt

Log Report For Auto Search And Install
Start Time : 11:54:25 AM
Start Date : 24/01/2015
Confirm : g2mui.exe
e:\app\g2mui.exe
Missing : Test.msi
Confirm : test.cmd
e:\gunsmokingman\desktop\test.cmd
No Action : test.cmd
e:\test.cmd
Confirm : misc.exe
c:\windows\installer\{90120000-0030-0000-0000-0000000ff1ce}\misc.exe
No Action : misc.exe
c:\windows\installer\{90120000-006e-0409-0000-0000000ff1ce}\misc.exe
No Action : misc.exe
d:\windows\installer\{90120000-0030-0000-0000-0000000ff1ce}\misc.exe
No Action : misc.exe
d:\windows\installer\{90120000-006e-0409-0000-0000000ff1ce}\misc.exe

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

  • Recently Browsing   0 members

    No registered users viewing this page.