Sign in to follow this  
Followers 0
telmob

Dealing with CMDLINE in shell explorer extension?

4 posts in this topic

#1 ·  Posted (edited)

I have the following registry entries added to windows explorer context menu.

Basically, they add entries to the context menu for .exe files, with the option to allow or block.

Here are the registry entries:

RegWrite("HKEY_CLASSES_ROOT\exefile\shell\SRP Enforcer", "MUIVerb", "REG_SZ", "SRP Enforcer")
RegWrite("HKEY_CLASSES_ROOT\exefile\shell\SRP Enforcer", "SubCommands", "REG_SZ", "Add to allow list;Add to block list")
RegWrite("HKEY_CLASSES_ROOT\exefile\shell\SRP Enforcer", "icon", "REG_SZ", @ScriptDir & "\Graphics\Protected.ico")

RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to allow list", "", "REG_SZ", "Add to allow list")
RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to allow list", "Icon", "REG_SZ", @ScriptDir & "\Graphics\Allowed.ico")
RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to allow list\command", "", "REG_SZ", @ScriptDir & "\SRPE Final.exe /allow")

RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to block list", "", "REG_SZ", "Add to block list")
RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to block list", "Icon", "REG_SZ", @ScriptDir & "\Graphics\Blocked.ico")
RegWrite($hklm & "\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Add to block list\command", "", "REG_SZ", @ScriptDir & "\SRPE Final.exe /block")

Now.... my problem is... how do i deal with both allow and block options?

This is not working for me: :(

If $CmdLine[0] = 1 Then
For $i = 1 To $CmdLine[0]
DoAllow()
Next
$sFileList = ''
ElseIf $CmdLine[0] = 2 Then
For $i = 1 To $CmdLine[0]
DoBlock()
Next
EndIf
Edited by telmob

Share this post


Link to post
Share on other sites



$CmdLine[1] is the actual parameter received. Try compiling this code:

If $CmdLine[1] = "/allow" Then
DoAllow()
ElseIf $CmdLine[1] = "/block" Then
DoBlock()
EndIf

Func DoAllow()
MsgBox(0, "", "You have chosen allowed")
EndFunc

Func DoBlock()
MsgBox(0, "", "You have chosen blocked")
EndFunc

MsgBox(0, "", "The actual parameter received was: " & $CmdLine[1])

And start the exe with a batch file like this:

test.exe /allow

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

The problem is that i'm dealing with single or multiple files. (sorry i haven't mentioned it before :( )

In the example i'm keeping notepad.exe open to keep the script running. It stops running when notepad closes.

Here it is (sorry its so long...):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Outfile=SRPE Final.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include
#include
#include 'WM_COPYDATA.au3'

Global $WriteRegAllow = 0
Global $sFileName, $sIDString, $hGUI, $fCheckOnly, $sData

Func Example()
Local $iFileSent = _WM_COPYDATA_Initial('UniqueIDString', Default) ; Start the communication process.
If @error Then
If Not _WM_COPYDATA_SendStart(StringReplace(StringStripWS($CmdLineRaw, 3), '"', '')) Then ; Send $CmdLineRaw if there is process already running.
MsgBox(4096, '2nd Instance: ' & @error, 'Seems there was an @error, but more than likely $CmdLineRaw was blank.' & @CRLF & @CRLF & $CmdLineRaw)
EndIf
Exit
EndIf

Local $aFileList = 0, $sFileList = ''

;~ If $CmdLine[0] >= 1 Then
If $CmdLine[1] = "/allow" Then
MsgBox("","","Allow")
$WriteRegAllow = 1
For $i = 1 To $CmdLine[0]
$sFileList &= $CmdLine[$i] & @CRLF
Next
$sFileList = ''
EndIf
If $CmdLine[1] = "/block" Then
MsgBox("","","Block")
$WriteRegBlock = 0
For $i = 1 To $CmdLine[0]
$sFileList &= $CmdLine[$i] & @CRLF
Next
$sFileList = ''
EndIf
;~ EndIf

While ProcessExists("notepad.exe") ;############################################################## ALTERAR ISTO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Switch GUIGetMsg()
Case $iFileSent ; If the WM_COPYDATA message is interecepted then add the data sent to notepad.
$sFileList = _WM_COPYDATA_SendShutdown($aFileList)
If $sFileList Then
$sFileList = StringStripWS($sFileList, 3) & @CRLF ; Strip trailing whitespace.
$sFileList = _AddToDisallow($aFileList)
EndIf
$aFileList = 0
$sFileList = ''
EndSwitch
WEnd

;~ _DeleteToDisallow()
;~ _ShellAll_Uninstall() ; Remove the running EXE from the Shell ContextMenu.
_WM_COPYDATA_Shutdown()

Return True
EndFunc ;==>Example

Func _AddToDisallow(ByRef $aArray)
;~ Local $fDisallow = Number(RegRead('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\', 'DisallowRun')) == 1
;~ If Not $fDisallow Then
;~ RegWrite('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\', 'DisallowRun', 'REG_DWORD', 1)
;~ EndIf
Local $iCount = 0, $iReturn = 0
For $i = 1 To $aArray[0]
If $WriteRegAllow = 0 Then ; If the file is an exe, then continue.
$aArray[$i] = _GetFilename($aArray[$i])
$iCount += 1
$iReturn += RegWrite('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun\', $aArray[$i], 'REG_SZ', $aArray[$i])
EndIf
If $WriteRegAllow = 1 Then ; If the file is an exe, then continue.
$aArray[$i] = _GetFilename($aArray[$i])
$iCount += 1
$iReturn += MsgBox("","","Allowed Added.")
EndIf
Next
If $iReturn = 0 And $iReturn = 0 Then
Return False
EndIf
Return $iCount == $iReturn
EndFunc ;==>_AddToDisallow

;~ Func _DeleteToDisallow()
;~ Local $iReturn = RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\', 'DisallowRun')
;~ $iReturn += RegDelete('HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\DisallowRun\')
;~ Return $iReturn == 2
;~ EndFunc ;==>_DeleteToDisallow

Func _GetFilename($sFileName)
Return StringRegExpReplace($sFileName, '^.*\\', '')
EndFunc ;==>_GetFilename

Func _WM_COPYDATA_Initial($sIDString, $hGUI, $fCheckOnly = Default)
_WM_COPYDATA_SetID($sIDString)
Local Const $vReturn = _WM_COPYDATA_Start($hGUI, $fCheckOnly)
Local Const $iError = @error
Local $hWnd = WinGetHandle('[REGEXPTITLE:(?m)^' & _WM_COPYDATA_GetID() & '$]')
$hWnd = HWnd(ControlGetText($hWnd, '', ControlGetHandle($hWnd, '', 'Edit1')))
_WM_COPYDATA_SetGUI($hWnd)
WinSetTitle($hWnd, '', 'START_PROCESS')
Return SetError($iError, 0, $vReturn)
EndFunc ;==>_WM_COPYDATA_Initial

Func _WM_COPYDATA_SendShutdown(ByRef $aArray)
If StringStripWS(_WM_COPYDATA_GetData(), 8) <> 'START_PROCESS' Then
Return SetError(1, 0, '')
EndIf

Local $aReturn[1] = [0], $aWinList = 0, $sData = '', $sReturn = ''
Do
$aWinList = WinList('[REGEXPTITLE:' & _WM_COPYDATA_GetID() & '__CHILD__' & '\d+]')
If @error Then
ExitLoop
EndIf
If $aWinList[0][0] Then
ReDim $aReturn[($aReturn[0] + 1) + $aWinList[0][0]]
For $i = 1 To $aWinList[0][0]
$sData = ControlGetText($aWinList[$i][1], '', ControlGetHandle($aWinList[$i][1], '', 'Edit1'))
If StringStripWS($sData, 8) Then
$aReturn[0] += 1
$aReturn[$aReturn[0]] = $sData
$sReturn &= $sData & @CRLF
EndIf
ControlSetText($aWinList[$i][1], '', ControlGetHandle($aWinList[$i][1], '', 'Edit1'), '')
Next
EndIf
Until $aWinList[0][0] == 0

ReDim $aReturn[($aReturn[0] + 1)]
$aArray = $aReturn
$aReturn = 0
WinSetTitle(_WM_COPYDATA_GetGUI(), '', 'START_PROCESS')
Return $sReturn
EndFunc ;==>_WM_COPYDATA_SendShutdown

Func _WM_COPYDATA_SendStart($sData)
Local Const $sTitle = _WM_COPYDATA_GetID() & '__CHILD__' & @AutoItPID
AutoItWinSetTitle($sTitle)
Local Const $hWait = WinGetHandle($sTitle)
If @error Then
Return SetError(1, 0, False)
EndIf
ControlSetText($hWait, '', ControlGetHandle($hWait, '', 'Edit1'), $sData)

If WinGetTitle(_WM_COPYDATA_GetGUI()) = 'START_PROCESS' Then
If _WM_COPYDATA_Send('START_PROCESS') Then
WinSetTitle(_WM_COPYDATA_GetGUI(), '', 'IN_PROCESS')
EndIf
EndIf

While 1
If StringStripWS(ControlGetText($hWait, '', ControlGetHandle($hWait, '', 'Edit1')), 8) == '' Then
ExitLoop
EndIf
Sleep(250)
WEnd
Return True
EndFunc ;==>_WM_COPYDATA_SendStart
Edited by telmob

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

How to debug, strip out my WM_COPY*** functions and follow the advice by abberration. Start small and then work up (big.) You will also want the same parsing rules when another application sends $CmdLineRaw to the parent application.

Edited by guinness

_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 04/09/2015

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