Jump to content



Photo

  • Please log in to reply
8 replies to this topic

#1 brink668

brink668

    Neowinian

  • Joined: 12-September 07

Posted 15 August 2014 - 16:17

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"




#2 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 16 August 2014 - 16:15

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


#3 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 17 August 2014 - 02:27

If this is what you want done
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
Attached File  G2MuiAddReg.vbs.txt   667bytes   4 downloads

#4 OP brink668

brink668

    Neowinian

  • Joined: 12-September 07

Posted 18 August 2014 - 14:23

Thanks I will have to try this out.



#5 OP brink668

brink668

    Neowinian

  • Joined: 12-September 07

Posted 18 August 2014 - 14:31

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



#6 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 18 August 2014 - 16:34

Are you trying to do this.
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" 


#7 OP brink668

brink668

    Neowinian

  • Joined: 12-September 07

Posted 19 August 2014 - 16:40

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



#8 almador

almador

    Resident One Post Wonder

  • Joined: 24-January 15

Posted 24 January 2015 - 12:26

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?



#9 jake1eye

jake1eye

    Neowinian

  • Joined: 02-April 03
  • Location: New Westminster

Posted 24 January 2015 - 20:00

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

 
When I was testing the script with \ in the pathway this occur
BackSlashChr.png  
Here is the registry with the 3 ways I could get.
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