Jump to content
Sign in to follow this  
Ruud0209

Dameware Protocol Handler - Feedback appreciated.

Recommended Posts

Ruud0209

Hi,

I've kind of created an URL protocol handler for the Dameware Mini Remote Control Program.

It allows remote control connections by use of entering an url like string so it can be used from web based applications/pages.

Since i'm not a good programmer I'd like some feedback on how to improve the script, for instance I think the commandline parameter handling can be done more efficiently and with less room for error.

Any help or comments is appreciated.

AutoItSetOption("TrayIconDebug", 0)
AutoItSetOption("Trayautopause", 0)
AutoItSetOption("TrayIconHide", 1)
Func OnAutoItStart()
    TraySetState(2)
    If $CmdLine[0] > "0" Then
        Select
            Case $CmdLineRaw = "/REMOVE"
                RegDelete("HKCR\rc")
                MsgBox(0, "Removed", "Darecup entries have been removed from the registry." & @CRLF & "Please remove the " & @ScriptName & " executable from the Dameware NT Utilities or Dameware Mini Remote Control directory manualy.")
                
                Exit
            Case $CmdLineRaw = "/HELP"
                _help()
                Exit
            Case Else
                ;;
                Dim $password
                If StringInStr($CmdLineRaw,"""") Then 
                $password=StringSplit($CmdLineRaw,"""",0)
                MsgBox(0,"debug",$password[2])
                Endif
                $CmdLineRaw = StringReplace($CmdLineRaw, "rc://", " -m:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "machine=", " -m:")
                ;$CmdLineRaw = StringReplace($CmdLineRaw, "help", " -?")
                $CmdLineRaw = StringReplace($CmdLineRaw, "/", "")
                $CmdLineRaw = StringReplace($CmdLineRaw, "&", "")
                $CmdLineRaw = StringReplace($CmdLineRaw, "?", "")
                $CmdLineRaw = StringReplace($CmdLineRaw, "username=", " -u:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "domain=", " -d:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "port=", " -o:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "secret=", " -s:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "auth=", " -a:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "rdp=", " -r:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "viewonly=", " -v:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "mirror=", " -md:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "instance=", " -i:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "autoclose=", " -x:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "autoconnect=", " -c: -h:")
                $CmdLineRaw = StringReplace($CmdLineRaw, "protocol=rdp", " -r:") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "monitor=viewonly", " -v:"); for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "connectiontype=autoconnect", " -c: -h:") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "closeondisconnect=autoclose", " -x:") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "mdriver=mirror", " -md:") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "debug=debug", " debug") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "protocol=", "") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "monitor=", ""); for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "connectiontype=", "") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "closeondisconnect=", "") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "mdriver=", "") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "debug=", "") ; for internet forms
                $CmdLineRaw = StringReplace($CmdLineRaw, "password=", " -p:" & $password)
                $CmdLineRaw = StringReplace($CmdLineRaw, "-m: -m:", "-m:")
                
                
                If StringInStr($CmdLineRaw,"debug") > 0 Then
                    $CmdLineRaw = StringReplace($CmdLineRaw, "debug", "") ; for internet forms
                    MsgBox(0, "Output", "Parameter : " & $CmdLineRaw & @CRLF & "Scriptdir : " & @ScriptDir)
                EndIf
                If RegRead("HKCR\rc", "") Then
                    Dim $installed
                    $installed = 1
                    If FileExists(@ScriptDir & "\DWRCC.EXE") Then
                        If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
                        If StringInStr($CmdLineRaw, "help") > 0 Then ; If help is in string then help
                            _help()
                        Else
                            Run(@ScriptDir & "\DWRCC.EXE " & $CmdLineRaw, @ScriptDir)
                            Exit
                        EndIf
                    Else
                        #Region --- CodeWizard generated code Start ---
                        ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Critical
                        MsgBox(16, "Required Program Not Found !", "DWRCC.exe was not found. Please check the parameter given or execute the program from the directory where the DWRCC.exe executable is located.")
                        #EndRegion --- CodeWizard generated code End ---
                        
                    EndIf
                Else
                    #Region --- CodeWizard generated code Start ---
                    ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question
                    If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
                    $iMsgBoxAnswer = MsgBox(36, "X-Arcade.nl presents : Darecup", @CRLF & "The Dameware URL protocol handler a.k.a. Darecup will allow you to connect to machines with the Dameware Remote Control utility by using regular urls. It adds a protocol handler in the registry (HKCR\rc) wich makes the magic happen." & _
                            @CRLF & "Once installed you can remote control a machine by entering rc://machine in the explorer adress bar. This also allows easy integration with webbased monitoring tools such as Whatsup Gold or even your own webbpages." & _
                            @CRLF & "You need to have the Dameware NT Utilities or at least the Dameware Remote Control Utility installed of course..." & _
                            @CRLF & "usage: rc://machine.domain.com?username=USERNAME&password=PASSWORD&domain=DOMAIN.COM&autoconnect&port=1234&rdp&secret=SHAREDSECRET&auth=1" & _
                            @CRLF & "or any combination of the parameters used in this example. Use rc://help for instant help." _
                             & @CRLF & "Run " & @ScriptName & " with /REMOVE parameter to uninstall" _
                             & @CRLF & "Run " & @ScriptName & " with /HELP parameter to view help" _
                             & @CRLF & @CRLF & "Do you want to install Darecup?")
                    Select
                        Case $iMsgBoxAnswer = 6 ;Yes
                            _Install()
                            Exit
                        Case $iMsgBoxAnswer = 7 ;No
                            MsgBox(48, "Not Installed", "You have chosen not to install Darecup")
                            Exit
                    EndSelect
                    #EndRegion --- CodeWizard generated code End ---
                EndIf
                
        EndSelect
    Else
        If RegRead("HKCR\rc", "") Then
            Dim $installed
            $installed = 1
            If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
            $iMsgBoxAnswer = MsgBox(48, "Darecup : The Dameware Remote Control URL Protocol Handler", @CRLF & "The Dameware URL protocol handler will allow you to connect to machines with the Dameware Remote Control utility by using regular urls. It adds a protocol handler in the registry (HKCR\rc) wich makes the magic happen." & _
                    @CRLF & "Once installed you can remote control a machine by entering rc://machine in the explorer adress bar. This also allows easy integration with webbased monitoring tools such as Whatsup Gold or even your own webbpages." & _
                    @CRLF & "You need to have the Dameware NT Utilities or at least the Dameware Remote Control Utility installed of course..." & _
                    @CRLF & "usage: rc://machine.domain.com?username=USERNAME&password=""PASSWORD""&domain=DOMAIN.COM&autoconnect&port=1234&&rdp&secret=SHAREDSECRET&auth=1&viewonly&mirror&instance=INSTANCEOVERRIDE&autoclose" & _
                    @CRLF & "or any combination of the parameters used in this example. Use rc://help for instant help." & @CRLF _
                     & @CRLF & "Run " & @ScriptName & " with /REMOVE parameter to uninstall" _
                     & @CRLF & "Run " & @ScriptName & " with /HELP parameter to view help")
        Else
            #Region --- CodeWizard generated code Start ---
            ;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Icon=Question
            If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
            $iMsgBoxAnswer = MsgBox(36, "X-Arcade.nl presents : The Dameware Remote Control URL Protocol Handler", @CRLF & "The Dameware URL protocol handler will allow you to connect to machines with the Dameware Remote Control utility by using regular urls. It adds a protocol handler in the registry (HKCR\rc) wich makes the magic happen." & _
                    @CRLF & "Once installed you can remote control a machine by entering rc://machine in the explorer adress bar. This also allows easy integration with webbased monitoring tools such as Whatsup Gold or even your own webbpages." & _
                    @CRLF & "You need to have the Dameware NT Utilities or at least the Dameware Remote Control Utility installed of course..." & _
                    @CRLF & "usage: rc://machine.domain.com?username=USERNAME&password=""PASSWORD""&domain=DOMAIN.COM&autoconnect&port=1234&rdp&secret=SHAREDSECRET&auth=1" & _
                    @CRLF & "or any combination of the parameters used in this example. Use rc://help for instant help." _
                     & @CRLF & "Run " & @ScriptName & " with /REMOVE parameter to uninstall" _
                     & @CRLF & "Run " & @ScriptName & " with /HELP parameter to view help" _
                     & @CRLF & @CRLF & "Do you want to install the Dameware Remote Control URL Protocol Handler ?")
            Select
                Case $iMsgBoxAnswer = 6 ;Yes
                    _Install()
                    Exit
                Case $iMsgBoxAnswer = 7 ;No
                    MsgBox(48, "Not Installed", "You have chosen not to install Darecup : The Dameware Remote Control URL Protocol Handler.")
                    Exit
            EndSelect
            #EndRegion --- CodeWizard generated code End ---
        EndIf
    EndIf
    
EndFunc   ;==>OnAutoItStart
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Func _Install()
    
    If IsAdmin() Then
        If FileExists(@ProgramFilesDir & "\DameWare Development\DameWare NT Utilities\DWRCC.exe") Then
            Dim $Hint
            $Hint = @ProgramFilesDir & "\DameWare Development\DameWare NT Utilities"
            
        ElseIf FileExists(@ProgramFilesDir & "\DameWare Development\DameWare Mini Remote Control\DWRCC.exe") Then
            Dim $Hint
            $Hint = @ProgramFilesDir & "\DameWare Development\DameWare Mini Remote Control"
        Else
            $Hint = @ProgramFilesDir
        EndIf
        
        $PathToInstall = FileSelectFolder("Select the directory where the Dameware Remote Control Utility is located.", @HomeDrive, 3, $Hint)
        If @error = 1 Then
            MsgBox(16, "Aborted", "The installation is canceled")
            Return 1
        EndIf
        
        ProgressOn("Installation progress", "Installing ... ", "0 procent")
        Sleep(500)
        ProgressSet(5, 5 & " percent")
        Sleep(50)
        RegWrite("HKEY_CLASSES_ROOT\rc", "", "REG_SZ", "URL: Dameware Remote Control Protocol")
        ProgressSet(10, 10 & " percent")
        RegWrite("HKEY_CLASSES_ROOT\rc", "URL Protocol", "REG_SZ", "")
        ProgressSet(30, 30 & " percent")
        RegWrite("HKEY_CLASSES_ROOT\rc\shell\open\command", "", "REG_SZ", """" & $PathToInstall & "\" & @ScriptName & """ " & " %1")
        ProgressSet(70, 70 & " percent")
        Sleep(50)
        FileCopy(@ScriptFullPath, $PathToInstall, 1)
        ProgressSet(100, "Ready", "Complete")
        Sleep(500)
        ProgressOff()
        MsgBox(64, "Darecup Installed", "The Dameware Remote Control URL Protocol Handler (Darecup) is now installed." & @CRLF & "To remove simply type " & $PathToInstall & "\" & @ScriptName & " /remove in command window.")
        Return 0
        Exit
    Else
        MsgBox(16, "Error !", "To install Darecup you need Admin rights !")
    EndIf
EndFunc   ;==>_Install
Func _help()
    #Region --- CodeWizard generated code Start ---
    ;MsgBox features: Title=Yes, Text=Yes, Buttons=OK, Icon=Info
    MsgBox(64, "Help", "You can use the rc:// (Dameware Remote Control URL) protocol handler just like the http:// protocol handler." _
             & @CRLF & "Just like with http you will first enter the servername or ipadress you want to connect to, followed by a bunch of parameters." _
             & @CRLF & "(As with http: the first is preceded by a ? and all subsequent are preceded by & ):" _
             & @CRLF & "Any combination is accepted and passed through to the Remote Control utility." _
             & @CRLF & "The matching original DWRCC.exe parameter is between brackets at the end of the line." _
             & @CRLF & "Parameters you can use:" _
             & @CRLF & @CRLF & "username=USERNAME        : specifies the username or loginname used to connect with.(-u:)" _
             & @CRLF & "password=""PASSWORD""       : specifies the password of the above mentioned username. (-p:)" _
             & @CRLF & "domain=DOMAIN                : specifies the domainname the use belongs to. (-d:)" _
             & @CRLF & "secret=SHAREDSECRET     : specifies the shared secret used. (-s:)" _
             & @CRLF & "port=PORTNUMBER            : specifies the portnumber (so use port=1234 if thats your port) (-o:)" _
             & @CRLF & "auth=LEVEL                         : specifies the authentication level [0,1,2]. (-a:)" _
             & @CRLF & "instance=N                          : Instance number override (where 0<N<40) (-i:)" _
             & @CRLF & "viewonly=                             : Open this session in View Only mode (-v:)" _
             & @CRLF & "mirror=                                  : Use mirror driver(-md:)" _
             & @CRLF & "rdp=                                    : Use rdp (MS Remote Desktop) protocol. (-r:)" _
             & @CRLF & "autoconnect=                       : Connects without login screen (if possible) (-c: -h:)" _
             & @CRLF & "autoclose=                            : Exit on disconnect (-x:)" _
             & @CRLF & "help=                                    : provides help on how to use the X-Arcade.nl Dameware Remote Control URL Protocol Handler." _
             & @CRLF & "------------------------------------------------------------------------------------------------------------------------------------------------------------------------" _
             & @CRLF & "Example: rc://my-machine?username=administrator&password=""45%6G&H?J*8""&autoconnect&autoclose" _
             & @CRLF & "This should open a remote control session to mymachine with username and password passed through and without displaying the MRC Host" & @CRLF & "Entry setting first. It will also close on disconnect." _
             & @CRLF & "------------------------------------------------------------------------------------------------------------------------------------------------------------------------" _
             & @CRLF & "Please note that some parameters require version 4.6 or higher of the Dameware Mini Remote Control Tool." _
             & @CRLF & "Also note that passwords with ?'s and &'s will not work as a parameter unless when put between double quotes." _
             & @CRLF & "The password paramater is the ONLY parameter for wich you can use quotes." _
             & @CRLF & "------------------------------------------------------------------------------------------------------------------------------------------------------------------------" _
             & @CRLF & "Dameware,Dameware NT Utilities and Dameware Mini Remote Control are registered trademarks of Dameware Development LLC" _
             & @CRLF & "------------------------------------------------------------------------------------------------------------------------------------------------------------------------" _
             & @CRLF & "Brought to you by X-Arcade.nl - Contact: info@x-arcade.nl" _
             & @CRLF & @CRLF & @CRLF)
    #EndRegion --- CodeWizard generated code End ---
EndFunc   ;==>_help
Edited by Ruud_Sas

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  

×