Jump to content



Photo

  • Please log in to reply
6 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   3 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.