Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/22/2014 in all areas

  1. I do like the alternative that trancexx provided. It does highlight the importance of a http user agent string that can be recognized. InetRead seems to be adequate with this example: ; Set http user agent. $sUserAgent = _HttpSetUserAgent() ; Show http user agent being used MsgBox(0, 'Http User Agent', $sUserAgent) ; Get binary data from this URL. 9 = Force reload with binary mode. $URL = "http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el" $dData = InetRead($URL, 9) ; Convert the binary to a string. 4 = UTF8. $sData = BinaryToString($dData, 4) ; Show the UTF8 string. MsgBox(0, $URL, $sData) Func _HttpSetUserAgent($sPreferredUserAgent = 'Mozilla/5.0', $bForcePreference = False) ; Set http user agent. Local $sUserAgent If Not $bForcePreference Then ; Places of reading the http user agent can vary. This is just one place. $sUserAgent = RegRead('HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings', 'User Agent') EndIf If $sUserAgent == '' Then Switch $sPreferredUserAgent Case Default, 'Mozilla/5.0' $sUserAgent = 'Mozilla/5.0' Case '' $sUserAgent = '' Case Else $sUserAgent = $sPreferredUserAgent EndSwitch EndIf HttpSetUserAgent($sUserAgent) Return SetError(@error, @extended, $sUserAgent) EndFunc ; http://msdn.microsoft.com/en-us/library/ms537503%28v=vs.85%29.aspx ; Quote: ; "Note The user-agent string should not be used to indicate the presence of optional software or features. ; Custom version vectors, which can be detected using conditional comments, provide a more appropriate mechanism." ; ; http://msdn.microsoft.com/en-us/library/hh869301%28v=vs.85%29.aspx ; Quote: ; "As with previous versions of Internet Explorer, portions of the user-agent string can vary according ; to the device running Internet Explorer, the operating system, and the environment." ; I doubt too many http servers will be looking for the http user agent string of "AutoIt" so IMO change it. Trident usually uses "Mozilla/4.0" or "Mozilla/5.0" with a possible features string appended. Output I get from testing: --------------------------- Http User Agent --------------------------- Mozilla/4.0 (compatible; MSIE 8.0; Win32) --------------------------- OK --------------------------- --------------------------- http://translate.google.com/translate_a/t?client=t&sl=auto&text=hometown+&tl=el --------------------------- [[["πατρίδα","hometown","patrída",""]],,"en",,[["πατρίδα",[1],true,false,572,0,1,0]],[["hometown",1,[["πατρίδα",572,true,false],["γενέτειρά",276,true,false],["hometown",128,true,false],["πόλη",13,true,false],["την πατρίδα",8,true,false]],[[0,8]],"hometown"]],,,[["en"]],3] --------------------------- OK ---------------------------
    2 points
  2. FireFox

    IP Camera stream + record

    I recently bought an IP Camera to monitor my house. There is a web access to view the video stream but not to record it. Here is the IP Camera in question, it should work with every other similar product. So I made a simple example which does the job. Here is the code : #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <WinAPI.au3> #include <GDIPlus.au3> #include <Memory.au3> #region Global Vars Global Const $sProgramTitle = "IP Camera stream + record" ;EDIT THE FOLLOWING LINE ONLY: Global Const $iIPAddress = "192.168.1.99", $iPort = 99, $shtauth = "yourauth==" Global Const $STM_SETIMAGE = 0x0172 Global $blRecording = False, $blGUIMinimized = False Global Const $sRecordDir = @ScriptDir & "\ip_camera_stream" Global $bRecvtmp = Binary(""), $bStream = $bRecvtmp Global $iImgLen = 0, $iStreamLen = 0, $iWritten = 0, $iEOH = 0, $iContLenPos = 0, $hImgFile = 0, $pBuffer = 0, $iImgCount = 0 Global Const $iContLengthLen = StringLen("Content-Length: ") Global $sStream = "", $sTrim2ContLen = "" Global $hBMP = 0, $hGraphics = 0, $hHBITMAP2 = 0, $hFamily = 0, $hFont = 0, $tLayout = "", $hFormat = 0, $hBrush = 0 #endregion Global Vars TCPStartup() Global $iSocket = TCPConnect($iIPAddress, $iPort) If @error Then MsgBox(16, $sProgramTitle, "Could not connect !") Exit -1 EndIf TCPSend($iSocket, _ "GET /videostream.cgi HTTP/1.1" & @CRLF & _ "Host: " & $iIPAddress & ":" & $iPort & @CRLF & _ "Connection: keep-alive" & @CRLF & _ "Authorization: Basic " & $shtauth & @CRLF & @CRLF) #region GUI Global $hGUI = 0, $pPic = 0, $hPic = 0, $btnRecord = 0 $hGUI = GUICreate($sProgramTitle, 640, 525) $pPic = GUICtrlCreatePic("", 0, 0, 640, 480, $SS_BITMAP) GUICtrlSetState($pPic, $GUI_DISABLE) $hPic = GUICtrlGetHandle($pPic) $btnRecord = GUICtrlCreateButton("Record", 10, 490, 80, 26) GUIRegisterMsg($WM_SYSCOMMAND, "WM_SYSCOMMAND") GUISetState(@SW_SHOW, $hGUI) #endregion GUI _GDIPlus_Startup() $hFamily = _GDIPlus_FontFamilyCreate("Arial") $hFont = _GDIPlus_FontCreate($hFamily, 17) $tLayout = _GDIPlus_RectFCreate(10, 10, 100, 40) $hFormat = _GDIPlus_StringFormatCreate() $hBrush = _GDIPlus_BrushCreateSolid(0xAFFF0000) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $btnRecord If $blRecording Then GUICtrlSetData($btnRecord, "Record") Else If Not FileExists($sRecordDir) Then DirCreate($sRecordDir) GUICtrlSetData($btnRecord, "Stop recording") EndIf $blRecording = Not $blRecording EndSwitch $bRecvtmp = TCPRecv($iSocket, 4096, 1) ;4kb If @error Then ExitLoop If Not BinaryLen($bRecvtmp) Then ContinueLoop $bStream &= $bRecvtmp If $iImgLen = 0 Then $sStream = BinaryToString($bStream) $iContLenPos = StringInStr($sStream, "Content-Length: ", 2) $iEOH = StringInStr($sStream, @CRLF & @CRLF, 2, 1, $iContLenPos) If $iEOH = 0 Or $iContLenPos = 0 Then ContinueLoop $sTrim2ContLen = StringTrimLeft($sStream, $iContLenPos + $iContLengthLen - 1) $iImgLen = Number(StringLeft($sTrim2ContLen, StringInStr($sTrim2ContLen, @CR, 2) - 1)) $bStream = BinaryMid($bStream, $iEOH + 4) EndIf If $iImgLen = 0 Then ContinueLoop $iStreamLen = BinaryLen($bStream) If $iStreamLen < $iImgLen Then ContinueLoop If Not $blGUIMinimized Then $hBMP = Load_BMP_From_Mem($bStream) If $blRecording Then $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBMP) _GDIPlus_GraphicsDrawStringEx($hGraphics, "[•REC]", $hFont, $tLayout, $hFormat, $hBrush) EndIf $hHBITMAP2 = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBMP) _WinAPI_DeleteObject(_SendMessage($hPic, $STM_SETIMAGE, 0, $hHBITMAP2)) _GDIPlus_ImageDispose($hBMP) If $blRecording Then _GDIPlus_GraphicsDispose($hGraphics) _WinAPI_DeleteObject($hHBITMAP2) EndIf If $blRecording Then $pBuffer = DllStructCreate("byte[" & $iImgLen & "]") If $iStreamLen > $iImgLen Then DllStructSetData($pBuffer, 1, BinaryMid($bStream, 1, $iImgLen)) $bStream = BinaryMid($bStream, $iImgLen) Else DllStructSetData($pBuffer, 1, $bStream) $bStream = Binary("") EndIf $hImgFile = _WinAPI_CreateFile($sRecordDir & "\snap_" & StringFormat("%.4d", $iImgCount) & ".jpg", 3, 4, 4) _WinAPI_WriteFile($hImgFile, DllStructGetPtr($pBuffer), $iImgLen, $iWritten) _WinAPI_CloseHandle($hImgFile) $iImgCount += 1 EndIf $iImgLen = 0 WEnd _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_Shutdown() TCPCloseSocket($iSocket) TCPShutdown() Func WM_SYSCOMMAND($hWnd, $iMsg, $wParam, $lParam) Local Const $SC_MINIMIZE = 0xF020, $SC_RESTORE = 0xF120 Switch BitAND($wParam, 0xFFF0) Case $SC_MINIMIZE, $SC_RESTORE $blGUIMinimized = Not $blGUIMinimized EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_SYSCOMMAND Func Load_BMP_From_Mem($bImage) ;_GDIPlus_BitmapCreateFromMemory2 ;Author: UEZ ;Modified: ProgAndy, Yashied, FireFox If Not IsBinary($bImage) Then Return 0 Local $memBitmap = Binary($bImage) Local $iLen = BinaryLen($memBitmap) Local $GMEM_MOVEABLE = 0x0002 Local $aResult = DllCall("kernel32.dll", "handle", "GlobalAlloc", "uint", $GMEM_MOVEABLE, "ulong_ptr", $iLen) Local $hData = $aResult[0] $aResult = DllCall("kernel32.dll", "ptr", "GlobalLock", "handle", $hData) If @error Then Return 0 Local $tMem = DllStructCreate("byte[" & $iLen & "]", $aResult[0]) DllStructSetData($tMem, 1, $memBitmap) DllCall("kernel32.dll", "bool", "GlobalUnlock", "handle", $hData) If @error Then Return 0 $aResult = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $hData, "int", True, "ptr*", 0) $hStream = $aResult[3] If @error Then Return 0 $aResult = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) If @error Then Return 0 DllCall('oleaut32.dll', 'long', 'DispCallFunc', 'ptr', $hStream, 'ulong_ptr', 8 * (1 + @AutoItX64), 'uint', 4, 'ushort', 23, 'uint', 0, 'ptr', 0, 'ptr', 0, 'str', '') Return $aResult[2] EndFunc ;==>Load_BMP_From_Mem _ Advanced example : Preview : Attachment : IP Camera.au3 IP Camera.au3 (Previous: 34 downloads) Enjoy, I'm watching U !
    1 point
  3. JohnOne

    _InstallMyApp UDF

    This code was to help me install files needed for a project which is regularly being updated with different files. If you drop the below .au3 file into your AutoIt3 project folder and run it, it will generate the code needed to install all the files and folders into the correct places for executable deployment. Blah blah.. here's the code... #include <File.au3> Global Const $MyAppName = "MyAppName" ; >>> You Must Alter This <<< Global Const $MyAppNameIni = $MyAppName & ".ini" _FileInstallAid() Func _FileInstallAid() ;I filtered out .au3 and .bak files for my needs, simple to change filter if needed $a = _FileListToArrayRec(@ScriptDir, "*|*.au3;*.bak", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_RELPATH) $s = '_InstallMyApp()' & @CRLF & @CRLF $s &= 'Func _InstallMyApp()' & @CRLF $s &= @TAB & 'If Int(IniRead("' & $MyAppNameIni & '", "' & $MyAppName & '", "Installed", "0")) Then' & @CRLF $s &= @TAB & @TAB & 'Return' & @CRLF $s &= @TAB & 'EndIf' & @CRLF $s &= @TAB & '_CreateFolders()' & @CRLF $s &= @TAB & '_FileInstall()' & @CRLF $s &= @TAB & 'IniWrite("' & $MyAppNameIni & '", "' & $MyAppName & '", "Installed", "1")' & @CRLF $s &= 'EndFunc' & @CRLF & @CRLF $s &= _CreateFoldersAid() $s &= 'Func _FileInstall()' & @CRLF & @TAB For $i = 1 To Int($a[0]) $s &= 'FileInstall("' & @ScriptDir & "\" & $a[$i] & '", @ScriptDir & "\' & $a[$i] & '")' & @CRLF & @TAB Next $s = StringTrimRight($s, 1) $s &= "EndFunc" & @CRLF & @CRLF ClipPut($s) Exit MsgBox(0, "Complete", "Code in Clipboard", 3) EndFunc ;==>_FileInstallAid Func _CreateFoldersAid() $a = _FileListToArrayRec(@ScriptDir, "*|*.au3", $FLTAR_FOLDERS, $FLTAR_RECUR, $FLTAR_NOSORT) For $i = Int($a[0]) To 1 Step -1 If $a[$i] == "BackUp" Then _ArrayDelete($a, $i) EndIf Next $a[0] = UBound($a) - 1 $s = 'Func _CreateFolders()' & @CRLF $s &= @TAB & 'Local $aFolders[' & UBound($a) - 1 & ']' & @CRLF For $i = 1 To Int($a[0]) $s &= @TAB & '$aFolders[' & $i - 1 & '] = "' & $a[$i] & '"' & @CRLF Next $s &= @TAB & 'For $i = 0 To Ubound($aFolders) - 1' & @CRLF $s &= @TAB & @TAB & 'If Not FileExists(@ScriptDir & "\" & $aFolders[$i]) Then' & @CRLF $s &= @TAB & @TAB & @TAB & 'DirCreate(@ScriptDir & "\" & $aFolders[$i])' & @CRLF $s &= @TAB & @TAB & 'EndIf' & @CRLF $s &= @TAB & 'Next' & @CRLF $s &= 'EndFunc' & @CRLF & @CRLF Return $s EndFunc ;==>_CreateFoldersAid I've done it many times, working on a project which uses many folders and files, then when I come to create an executable, I have to either zip all the folders and files with the exe or start writing the FileInstall code. Many people will say, it's easier to zip them, better to add them as resources or base64 binary embedded. And they might all be correct. But regardless of that it's just personal preference for me. If you need a code generator for just one folder then >see here. Below is a zipped file with some ready made files and folders for you to test with if you wish. How to use: It's quite simple, when your script is working how you want, then clear any crap out of the project folder (yes, it should be in its own folder, if it is in say the root c drive then you'll be distributing all those files on that drive NOT GOOD) Copy the InstallAid.au3 to you project root folder and run it. Generated code will be in your clipboard. Paste it into your main script file, move the globals near the top, and the functions wherever you like, be sure to add the name of your application, and you should move the "_InstallMyApp()" function to be ran before any other code except globals. As per my ethic the code is very very basic and should be simple to follow. EDIT: well it appears basic here, only because the real code is in the _FileListToArrayRec function, Thanks to big M23. EDIT2: below is an example of the code generated within the attached test folder. _InstallMyApp() Func _InstallMyApp() If Int(IniRead("MyAppName.ini", "MyAppName", "Installed", "0")) Then Return EndIf _CreateFolders() _FileInstall() IniWrite("MyAppName.ini", "MyAppName", "Installed", "1") EndFunc Func _CreateFolders() Local $aFolders[4] $aFolders[0] = "Folder1" $aFolders[1] = "Folder2" $aFolders[2] = "Folder3" $aFolders[3] = "Folder1\Folder1SubFolder" For $i = 0 To Ubound($aFolders) - 1 If Not FileExists(@ScriptDir & "\" & $aFolders[$i]) Then DirCreate(@ScriptDir & "\" & $aFolders[$i]) EndIf Next EndFunc Func _FileInstall() FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\RootFile1.txt", @ScriptDir & "\RootFile1.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\RootFile2.txt", @ScriptDir & "\RootFile2.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder3\Folder3File1.txt", @ScriptDir & "\Folder3\Folder3File1.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder2\Folder2File1.txt", @ScriptDir & "\Folder2\Folder2File1.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder2\Folder2File2.txt", @ScriptDir & "\Folder2\Folder2File2.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder1\Folder1File1.txt", @ScriptDir & "\Folder1\Folder1File1.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder1\Folder1File2.txt", @ScriptDir & "\Folder1\Folder1File2.txt") FileInstall("C:\Documents and Settings\John\Documents\MY_CODE\AU3\TestScripts\MyAppInstallFolder\Folder1\Folder1SubFolder\Folder1SubFolderFile1.txt", @ScriptDir & "\Folder1\Folder1SubFolder\Folder1SubFolderFile1.txt") EndFunc MyAppInstallFolder.zip
    1 point
  4. @hehehaha, how your skill level of PHP & JSON?
    1 point
  5. I said /S, not /s. For AutoIt, it works (NSIS package), but for InstallShield, I'm not sure... What is the application ? Can we download it somewhere ?
    1 point
  6. What do you use for repackaging, or do you normally just script the available installer? I know AdminStudio has a module that will let you tear an installer apart to write your own uninstaller if you need.
    1 point
  7. Usually silent uninstall works with MSI installers, but MSI installs should show up on WMIC. There is a tool that I use to force uninstall programs and it will scrub the registry for any associated entries that might help you isolate what you need. The tool is called "revo uninstaller". Its kinda a pain to find a bloatware free version, but you can get one here (its under utilities). You could try to call the uninstaller with -help, --help, /? or things of those nature and maybe there is a help file that will list the variables that are available.
    1 point
  8. 1 point
  9. @M23 - Thank you (...bowing to the God of Gui's...)
    1 point
  10. You can actually do this via command line (which you can invoke in autoit). You can use wmic and the uninstall command on most programs. EX: $wmiccommand = 'wmic product where name="windows live writer" call uninstall' RunWait('"' & @ComSpec & '" /c '&$wmiccommand, '', @SW_HIDE) More about wmic
    1 point
  11. Jewtus, Rather than use a HotKey I would do it like this: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> $Form1 = GUICreate("Form1", 623, 114, 192, 114) $Input1 = GUICtrlCreateInput("Input1", 56, 48, 121, 21) $Input2 = GUICtrlCreateInput("Input2", 240, 48, 121, 21) $Button1 = GUICtrlCreateButton("Button1", 424, 48, 75, 25) $cEnterDummy = GUICtrlCreateDummy() GUISetState(@SW_SHOW) ; Set Accelerator key Local $aAccelKeys[1][2] = [["{ENTER}", $cEnterDummy]] GUISetAccelerators($aAccelKeys) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $cEnterDummy ; Clear flag $bOK = False ; See what has focus Switch _WinAPI_GetFocus() Case GUICtrlGetHandle($Input1), GUICtrlGetHandle($Input2) If GUICtrlRead($Input1) <> '' Or GUICtrlRead($Input2) <> '' Then ; Set flag $bOK = True EndIf EndSwitch ; If flag set then fire the button If $bOK Then ContinueCase Case $Button1 MsgBox(0,"","test") EndSwitch WEnd Please ask if you have any questions. M23
    1 point
  12. Greetings! So I found a device named "X10 RF Remote Receiver" along with the remote in an old PC and it was connected to the motherboard with a 4-pole connector, so I soldered a USB plug on it and plugged it into my laptop - and it worked! But since programs don't usually come with support for all kinds of HIDs, this needed a little bit of software inbetween the drivers and whatever I want to control. After a few hours, I ran into a .NET tool that translated the remote signals into keystrokes, tailored to a wide variety of programs. Except they wanted money for it. After the free trial expired, my remote was once again useless, except for arrow keys and the power button. But today I managed to get hold of the raw signals! TL;DR: If your PC has an X10 type remote (and many other models are said to be compatible, I just can't guarantee this will work) and you've been wanting to directly control a script with it, this code is for you! (I seriously hope this is something new) First, you need the ActiveHome PRO SDK. After you've installed it, you can listen for key press events in your AutoIt script: $x10 = ObjCreate("X10.ActiveHome") If @error Then MsgBox(0,"",@error) EndIf $x10event = ObjEvent($x10, "_x10event", "_DIActiveHomeEvents") If @error Then MsgBox(0,"",Hex(@error)) Exit EndIf Func _x10eventRecvAction($parameter1,$parameter2,$parameter3,$parameter4,$parameter5,$parameter6,$parameter7) ConsoleWrite($parameter1 & @CRLF & $parameter2 & @CRLF & $parameter3 & @CRLF & $parameter4 & @CRLF & $parameter5 & @CRLF & $parameter6 & @CRLF & $parameter7) EndFunc While 1 Sleep(10) WEnd Your computer might still interpret remote key presses as keystrokes. To disable that, open your Control Panel and locate the Remote Control menu: Press any key on the remote to see which channel it sends on, then tell it to accept commands only from a different channel. The script will still work fine and Windows will leave you alone! Edit: It even survives unplugging and re-plugging the receiver. In fact, it fires a DeviseStop/DeviceStart event! Translating key presses on the remote into useful things is left as an exercise for the reader.
    1 point
  13. Recently I have had to deal with a lot of customers who want to send documents to a share on their own PC. Keep in mind I always recommend using a server for SMB shares however, some people don't have a server or enough people to warrant having a server. I made the following so that my technician can have this on a flash drive and it will create a share exactly the same way each time so I know what was done in case there is an issue. It will create the share (If it exists then it does not change the share called scan) It will create the user (if the user exists it will not modify that user) It will create a password for that user (If the user exists it will not change anything) It will create a shortcut to the share on the desktop It will grant the user full rights to the share both in permissions and security I hope you find it useful. It can probably be made cleaner but it does work for me so I don't mess with it too much. It will also create a TXT doc on the screen for the tech to use and a TXT file on the flash drive as a backup so they will know what was done. BTW, I just realized that I have a myshortcut.vbs file that gets installed. The VBS is noted in the notes in the script so you can make it if you want or incorporate it. #cs Creates a folder on the root of C: called scans Creates a local user scan on the PC Attempts to create a share called scans based on the folder above, if it already exists then it does nothing Adds full control to everyone adds scan user full permissions to the share Pops up a notepad with the information for the customer to save and the tech to read off or print out Since I do not know what the actual folder name is of the share I cannot create a shortcut Created on a workstations create a shortcut using the unc \\@computername\scans VBS Stuff in case I am on a PC that does not have the script: --------------------------------- set WshShell = WScript.CreateObject("WScript.Shell" ) set oShellLink = WshShell.CreateShortcut(Wscript.Arguments.Named("shortcut") & ".lnk") oShellLink.TargetPath = Wscript.Arguments.Named("target") oShellLink.WindowStyle = 1 oShellLink.Save --------------------------------- #ce #include <array.au3> #include <string.au3> #include <FileConstants.au3> #include <MsgBoxConstants.au3> #include <File.au3> ; Declare vars ----------------------------------------- #Region Declare Variables Global $ver = "1.051" Global $uName = "scan" Global $hName = @ComputerName Global $lPath = "C:\scans" Global $tFname = "deleteme.txt" Global $sName = "scans" Global $uPassword = "Scanningpass" Local $cntr = 1 Global $shareCmdE = "net share scans=" & $lPath & " /grant:everyone,FULL" Global $shareCmdS = "cacls " & $lPath & " /T /E /G " & $uName & ":f" Global $userCmds = "net user " & $uName & " " & $uPassword & " /ADD /FULLNAME:Scan_Acct" Local $iFileExists = FileExists ($lPath&"\"&$tFname) ; Get the customer name Global $cName = InputBox(" Customer Name", "Please enter the Customer Name:","","") Global $subject = """Scan setup for " & $cName & " <- Company""" Global $cFile = @ScriptDir & "\" & $cname & "\" & $cName & "_scans.txt" Global $txt = "Share name: \\" & @ComputerName & "\" & $sName & @CR & "User: " & $uName & @CR & "Password: " & $uPassword & @CRLF & "Please save for future reference" & @CR & "Version: " & $ver Global $txtEmail = """Share name: \\" & @ComputerName & "\" & $sName & " ""& vbCRLF & """ & "User: " & $uName & " ""& vbCRLF & """ & "Password: " & $uPassword & """ & vbCRLF & """ & "OS: " & @OSARCH & " - " & @UserName & " - " & @OSVersion & """ & vbCRLF & """ & "Version: " & $ver & " """ #EndRegion #Region Start_of_Program FileInstall( "C:\mkshortcut.vbs", @ScriptDir&"\mkshortcut.vbs", 1) NameofCompany() If $iFileExists Then makeshare() Else FileOpen($lPath&"\"&$tFname,9) makeshare() EndIf FileClose( $cFile ) FileClose($lPath&"\"&$tFname) FileDelete($lPath&"\"&$tFname) #EndRegion Func NameofCompany() ;$nowild = 1 $nowildq = StringInStr( $cName, "?") $nowildstar = StringInStr( $cName, "*") $nowildbk = StringInStr( $cName, "\") $nowildfwd = StringInStr( $cName, "/") $nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar ;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar) While $nowild <> 0 $nowildq = StringInStr( $cName, "?") $nowildstar = StringInStr( $cName, "*") $nowildbk = StringInStr( $cName, "\") $nowildfwd = StringInStr( $cName, "/") $nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar ;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar) Global $cName = InputBox(" Customer Name", "Name cannot contain * ? / or \" & @CRLF & "Please enter the Customer Name:","","") $nowildq = StringInStr( $cName, "?") $nowildstar = StringInStr( $cName, "*") $nowildbk = StringInStr( $cName, "\") $nowildfwd = StringInStr( $cName, "/") $nowild = $nowildbk + $nowildfwd + $nowildq + $nowildstar ;MsgBox (0,"Nowild", $nowild & @CRLF & "$nowildstar: " & $nowildstar) WEnd ;MsgBox(0,"test", $nowild & @CRLF & $cname) EndFunc Func makeshare() RunWait( @ComSpec & " /c" & $usercmds, @ScriptDir, @SW_HIDE) RunWait( @ComSpec & " /c" & $sharecmde, @ScriptDir, @SW_HIDE) RunWait( @ComSpec & " /c" & $sharecmds, @ScriptDir, @SW_HIDE) RunWait( @ComSpec & " /c" & "mkshortcut /target:""\\" & $hName & "\" & $sName & """ /shortcut:""ScannedDocs""", @ScriptDir, @SW_HIDE) FileCopy( @ScriptDir & "\ScannedDocs.lnk",@DesktopCommonDir & "\ScannedDocs.lnk") FileOpen ( $cFile, 9) FileWriteLine ($cFile, $txt) FileClose ($cfile) Run("notepad.exe") WinWaitActive("Untitled - Notepad") Send ( $txt ) FileDelete(@ScriptDir&"\ScannedDocs.lnk") FileDelete(@ScriptDir&"\mkshortcut.vbs") EndFunc
    1 point
  14. I've had this thing I wrote up laying around for a while now and decided I'd comment the heck out of it and post it here for others to enjoy as well. It's a multi-client TCP server "base" that has all the boilerplate code done, the only thing that one needs to do is just whip their protocol code in to it and it's ready to go. I've included a little few-line example bit in it (in the #region stuff) for a simple echo server. A quick way to see the example work is to just start this up and use a telnet client to connect to it on the port that you chose to have it bind (default in the one I'm posting is port 8080), typing a sentence, and pressing enter. This server makes use of setting the TCPTimeout option to 0, making it quite efficient when a high number of clients are connected and making it faster at accepting new connections. It does not use a fixed-size array for storing client connections, but instead dynamically re-sizes the client array when clients disconnect or connect (Setting $MaxClients to 0 makes the number of simultaneous clients only limited by RAM or AutoIt internal limits, whatever is reached first. I've tested this at 10,000 concurrent connections successfully, albeit with some slightly elevated CPU usage ). The server also implements a simple per-client packet buffer (as shown in the little echo example) which can come in handy for things such as large packets from file transferring and such. Instead of only relying on checking @error after a TCPRecv call to determine if a client disconnected (which can lie in certain cases), this uses a checking function which implements both that @error check and an idle timeout check that disconnects the client if they have not sent anything in a certain period of time. This is not really aimed at people who are unfamiliar with sockets work in AutoIt, as this provides no real application layer protocol, you must make that yourself. The only thing this does is do all the hard and/or tedious work of managing what happens when clients try connecting, how packet data should be buffered, and when a connection should be considered "dead". If you use this in a project, a simple little comment saying you used it would be nice #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.8.1 (Or greater) Author: Ken Piper Script Function: Template multi-client server base code. Use as a base for making an efficient server program. This base will just accept connections and echo back what it receives, and kill the connection if it is dead or inactive for x seconds. It will not do any other work, that must be added seperately! #ce ---------------------------------------------------------------------------- TCPStartup() Opt("TCPTimeout", 0) #region ;Safe-to-edit things are below Global $BindIP = "0.0.0.0" ;Listen on all addresses Global $BindPort = 8080 ;Listen on port 8080 Global $Timeout = 15000 ;Max idle time is 15 seconds before calling a connection "dead" Global $PacketSize = 2048 ;Max packet size per-check is 2KB Global $MaxClients = 50 ;Max simultaneous clients is 50 #endregion ;Stuff you shouldn't touch is below Global $Listen Global $Clients[1][4] ;[Index][Socket, IP, Timestamp, Buffer] Global $Ws2_32 = DllOpen("Ws2_32.dll") ;Open Ws2_32.dll, it might get used a lot Global $NTDLL = DllOpen("ntdll.dll") ;Open ntdll.dll, it WILL get used a lot Global $CleanupTimer = TimerInit() ;This is used to time when things should be cleaned up OnAutoItExitRegister("Close") ;Register this function to be called if the server needs to exit $Clients[0][0] = 0 $Listen = TCPListen($BindIP, $BindPort, $MaxClients) ;Start listening on the given IP/port If @error Then Exit 1 ;Exit with return code 1 if something was already bound to that IP and port While 1 USleep(5000, $NTDLL) ;This is needed because TCPTimeout is disabled. Without this it will run one core at ~100%. ;The USleep function takes MICROseconds, not milliseconds, so 1000 = 1ms delay. ;When working with this granularity, you have to take in to account the time it takes to complete USleep(). ;1000us (1ms) is about as fast as this should be set. If you need more performance, set this from 5000 to 1000, ;but doing so will make it consume a bit more CPU time to get that extra bit of performance. Check() ;Check recv buffers and do things If TimerDiff($CleanupTimer) > 1000 Then ;If it has been more than 1000ms since Cleanup() was last called, call it now $CleanupTimer = TimerInit() ;Reset $CleanupTimer, so it is ready to be called again Cleanup() ;Clean up the dead connections EndIf Local $iSock = TCPAccept($Listen) ;See if anything wants to connect If $iSock = -1 Then ContinueLoop ;If nothing wants to connect, restart at the top of the loop Local $iSize = UBound($Clients, 1) ;Something wants to connect, so get the number of people currently connected here If $iSize - 1 > $MaxClients And $MaxClients > 0 Then ;If $MaxClients is greater than 0 (meaning if there is a max connection limit) then check if that has been reached TCPCloseSocket($iSock) ;It has been reached, close the new connection and continue back at the top of the loop ContinueLoop EndIf ReDim $Clients[$iSize + 1][4] ;There is room for a new connection, allocate space for it here $Clients[0][0] = $iSize ;Update the number of connected clients $Clients[$iSize][0] = $iSock ;Set the socket ID of the connection $Clients[$iSize][1] = SocketToIP($iSock, $Ws2_32) ;Set the IP Address the connection is from $Clients[$iSize][2] = TimerInit() ;Set the timestamp for the last known activity timer $Clients[$iSize][3] = "" ;Blank the recv buffer WEnd Func Check() ;Function for processing If $Clients[0][0] < 1 Then Return ;If there are no clients connected, stop the function right now For $i = 1 To $Clients[0][0] ;Loop through all connected clients $sRecv = TCPRecv($Clients[$i][0], $PacketSize) ;Read $PacketSize bytes from the current client's buffer If $sRecv <> "" Then $Clients[$i][3] &= $sRecv ;If there was more data sent from the client, add it to the buffer If $Clients[$i][3] = "" Then ContinueLoop ;If the buffer is empty, stop right here and check more clients $Clients[$i][2] = TimerInit() ;If it got this far, there is data to be parsed, so update the activity timer #region ;Example packet processing stuff here. This is handling for a simple "echo" server with per-packet handling $sRecv = StringLeft($Clients[$i][3], StringInStr($Clients[$i][3], @CRLF, 0, -1)) ;Pull all data to the left of the last @CRLF in the buffer ;This does NOT pull the first complete packet, this pulls ALL complete packets, leaving only potentially incomplete packets in the buffer If $sRecv = "" Then ContinueLoop ;Check if there were any complete "packets" $Clients[$i][3] = StringTrimLeft($Clients[$i][3], StringLen($sRecv) + 1) ;remove what was just read from the client's buffer $sPacket = StringSplit($sRecv, @CRLF, 1) ;Split all complete packets up in to an array, so it is easy to work with them For $j = 1 To $sPacket[0] ;Loop through each complete packet; This is where any packet processing should be done TCPSend($Clients[$i][0], "Echoing line: " & $sPacket[$j] & @CRLF) ;Echo back the packet the client sent Next #endregion ;Example Next EndFunc Func Cleanup() ;Clean up any disconnected clients to regain resources If $Clients[0][0] < 1 Then Return ;If no clients are connected then return Local $iNewSize = 0 For $i = 1 To $Clients[0][0] ;Loop through all connected clients $Clients[$i][3] &= TCPRecv($Clients[$i][0], $PacketSize) ;Dump any data not-yet-seen in to their recv buffer If @error > 0 Or TimerDiff($Clients[$i][2]) > $Timeout Then ;Check to see if the connection has been inactive for a while or if there was an error TCPCloseSocket($Clients[$i][0]) ;If yes, close the connection $Clients[$i][0] = -1 ;Set the socket ID to an invalid socket Else $iNewSize += 1 EndIf Next If $iNewSize < $Clients[0][0] Then ;If any dead connections were found, drop them from the client array and resize the array Local $iSize = UBound($Clients, 2) - 1 Local $aTemp[$iNewSize + 1][$iSize + 1] Local $iCount = 1 For $i = 1 To $Clients[0][0] If $Clients[$i][0] = -1 Then ContinueLoop For $j = 0 To $iSize $aTemp[$iCount][$j] = $Clients[$i][$j] Next $iCount += 1 Next $aTemp[0][0] = $iNewSize $Clients = $aTemp EndIf EndFunc Func Close() DllClose($Ws2_32) ;Close the open handle to Ws2_32.dll DllClose($NTDLL) ;Close the open handle to ntdll.dll For $i = 1 To $Clients[0][0] ;Loop through the connected clients TCPCloseSocket($Clients[$i][0]) ;Force the client's connection closed Next TCPShutdown() ;Shut down networking stuff EndFunc Func SocketToIP($iSock, $hDLL = "Ws2_32.dll") ;A rewrite of that _SocketToIP function that has been floating around for ages Local $structName = DllStructCreate("short;ushort;uint;char[8]") Local $sRet = DllCall($hDLL, "int", "getpeername", "int", $iSock, "ptr", DllStructGetPtr($structName), "int*", DllStructGetSize($structName)) If Not @error Then $sRet = DllCall($hDLL, "str", "inet_ntoa", "int", DllStructGetData($structName, 3)) If Not @error Then Return $sRet[0] EndIf Return "0.0.0.0" ;Something went wrong, return an invalid IP EndFunc Func USleep($iUsec, $hDLL = "ntdll.dll") ;A rewrite of the _HighPrecisionSleep function made by monoceres (Thanks!) Local $hStruct = DllStructCreate("int64") DllStructSetData($hStruct, 1, -1 * ($iUsec * 10)) DllCall($hDLL, "dword", "ZwDelayExecution", "int", 0, "ptr", DllStructGetPtr($hStruct)) EndFunc Comments, questions, and criticisms are appreciated! Changelog: Cleared up formatting a bit in the [autoit] tags Fixed a bug in how it cleaned up the connection, and fixed a spelling error in the post Fixed a very rare corner-case that could cause a crash when getting many connections and disconnections in a short amount of time Changed a bit of code to fix issues with reading multiple buffered packets Fixed some spelling in the post and clean the code a bit; I try to keep this code up-to-date with the source file on my computer Fixed to add a massive performance increase when handling large numbers of connected clients and the client array needs to be trimmed. (I've seen up to a 500x speed increase on my computer!) Quick fix, apparently I forgot to set the max pending connections in TCPListen, leading for some pretty slow connection-accepting! Sorry about that. Fixed the problem of the latest AutoIt version causing "If @error Then" type statements to fail for TCPRecv, as TCPRecv now sets @error to -1 if the socket is alive but idle. This fixes the problem of clients getting instantly disconnected, sorry about not updating the code here with this sooner.
    1 point
  15. This is a method to test connectivity to the Internet using the same approach as Mircosoft does, therefore no need to contact third party sites such as google or bing, which has often been the case. Function: ; #FUNCTION# ==================================================================================================================== ; Name ..........: _MicrosoftInternetConnectivity ; Description ...: Test if the local machine is connected to the Internet using the same method as Microsoft for 'network awareness' minus the dns records verification. ; Syntax ........: _MicrosoftInternetConnectivity() ; Parameters ....: None ; Return values .: Success: True ; Failure: False ; Author ........: guinness ; Remarks .......: This will contact the website www.msftncsi.com. Works with Windows 2000+ ; Requires TCPStartup() to be initialised. ; The function has a restriction of contacting Microsoft every 15 seconds, so if you call the function within a tight loop then the last response will ; be returned and @extended set to non-zero. ; Link ..........: http://technet.microsoft.com/en-us/library/cc766017(v=ws.10).aspx#BKMK_How ; Example .......: Yes ; =============================================================================================================================== Func _MicrosoftInternetConnectivity() Local Static $hTimer = 0, _ ; Create a static variable to store the timer handle. $bLastResponse = Null ; Create a static variable to store the last response. If TimerDiff($hTimer) < 15000 And Not ($bLastResponse = Null) Then ; If still in the timer and $bLastResponse contains a value. Return SetExtended(1, $bLastResponse) ; Return the last response instead and set @extended to 1. EndIf Local $bEnableActiveProbing = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'EnableActiveProbing') > 0 If @error Then $bEnableActiveProbing = True EndIf If Not $bEnableActiveProbing Then Return False EndIf Local $sContent = 'Microsoft NCSI', _ $sDNSHost = 'dns.msftncsi.com', _ $sDNSIPAddress = '131.107.255.255', _ $sURL = 'http://' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeHost') & '/' & RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbePath') If $sURL == 'http:///' Then $sURL = 'http://www.msftncsi.com/ncsi.txt' Else $sContent = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveWebProbeContent') $sDNSIPAddress = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeContent') $sDNSHost = RegRead('HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\NlaSvc\Parameters\Internet\', 'ActiveDnsProbeHost') EndIf $bLastResponse = BinaryToString(InetRead($sURL, $INET_FORCERELOAD)) == $sContent And TCPNameToIP($sDNSHost) == $sDNSIPAddress Return $bLastResponse EndFunc ;==>_MicrosoftInternetConnectivity Example use of Function: #include <InetConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() TCPStartup() Local $bConnected = _MicrosoftInternetConnectivity() MsgBox($MB_SYSTEMMODAL, '', 'Is the Internet working?: ' & ($bConnected ? 'Yes, the Internet is working.' : 'No, the Internet isn''t working.')) TCPShutdown() EndFunc ;==>Example
    1 point
×
×
  • Create New...