Jump to content

Recommended Posts

Well. I was needing to create a networks shortcut. so I did find anything into the forum. So I write this after reading about Nonfile Object.

 

;~ Danyfirex 26/07/2015
#include <WinAPIShellEx.au3>

Opt("MustDeclareVars", 1)

Global Const $SHCONTF_NONFOLDERS = 0x00040
Global Const $SHGDN_NORMAL = 0
Global Const $S_OK = 0
Global Const $sTagSTRRET = "UINT uType;ptr pOleStr;UINT uOffset;CHAR cStr[256]"


Global Const $CLSID_ShellLink = "{00021401-0000-0000-C000-000000000046}"
Global Const $sIID_IShellLinkW = "{000214F9-0000-0000-C000-000000000046}"
Global Const $sTagIShellLink = "getpath hresult(long;long;long;long); " & _
        "getidlist hresult(ptr); " & _
        "setidlist hresult(ptr); " & _
        "getdescription hresult(long;long); " & _
        "setdescription hresult(wstr); " & _
        "getworkingdirectory hresult(long;long); " & _
        "setworkingdirectory hresult(long); " & _
        "getarguments hresult(long;long); " & _
        "setarguments hresult(ptr); " & _
        "gethotkey hresult(long); " & _
        "sethotkey hresult(word); " & _
        "getshowcmd hresult(long); " & _
        "setshowcmd hresult(int); " & _
        "geticonlocation hresult(long;long;long); " & _
        "seticonlocation hresult(wstr;int); " & _
        "setrelativepath hresult(long;long); " & _
        "resolve hresult(long;long); " & _
        "setpath hresult(wstr)"

Global Const $sIID_IPersistFile = "{0000010b-0000-0000-C000-000000000046}"
Global Const $sTagIPersistFile = "GetClassID hresult(long); IsDirty hresult(); Load hresult(long;long); Save hresult(wstr;bool); SaveCompleted hresult(long); GetCurFile hresult(long)"

Global Const $sIID_IEnumIDList = "{000214F2-0000-0000-C000-000000000046}"
Global Const $sTagIEnumIDList = "Next hresult(ulong;ptr*;ulong*);" & _
        "Reset hresult();" & _
        "Skip hresult(ulong);" & _
        "Clone hresult(ptr*);"

Global Const $sIID_IShellFolder = "{000214E6-0000-0000-C000-000000000046}"
Global Const $sTagIShellFolder = "ParseDisplayName hresult(hwnd;ptr;wstr;ulong*;ptr*;ulong*);" & _
        "EnumObjects hresult(hwnd;dword;ptr*);" & _
        "BindToObject hresult(ptr;ptr;clsid;ptr*);" & _
        "BindToStorage hresult(ptr*;ptr;clsid;ptr*);" & _
        "CompareIDs hresult(lparam;ptr*;ptr*);" & _
        "CreateViewObject hresult(hwnd;clsid;ptr*);" & _
        "GetAttributesOf hresult(uint:ptr*;ulong*);" & _
        "GetUIObjectOf hresult(hwnd;uint;ptr*;clsid;uint*;ptr*);" & _
        "GetDisplayNameOf hresult(ptr;dword;ptr);" & _
        "SetNameOf hresult(hwnd;ptr*;wstr;dword;ptr*);"


Local $MyNetWorkConnectionName="Conexión de red inalámbrica"
CreateNetWorkConnectionShortCut($MyNetWorkConnectionName)

;~ Success: Return True
;~ Failure: Return False
;~ if $lnkPath = "" ShortCut will be Create on Desktop with the name of the Conections($sConnectionName)
Func CreateNetWorkConnectionShortCut($sConnectionName, $lnkPath = "")
    Local $pConecctionsFolder = 0
    Local $oConecctionsFolder = 0
    Local $pEnumIDList = 0
    Local $oEnumIDList = 0
    Local $pPIDLItem = 0
    Local $celtFetched = 0
    Local $pPIDLConectionsFolder = 0
    Local $bRet = False
    Local $tSTRRET = 0
    Local $twstring = 0
    Local $pShellFolder = SHGetDesktopFolder()
    Local $oShellFolder = ObjCreateInterface($pShellFolder, $sIID_IShellFolder, $sTagIShellFolder)
    If @error Then Return $bRet
    $pPIDLConectionsFolder = _WinAPI_ShellGetSpecialFolderLocation($CSIDL_CONNECTIONS)
    If SUCCEEDED($oShellFolder.BindToObject($pPIDLConectionsFolder, Null, $sIID_IShellFolder, $pConecctionsFolder)) Then
        $oConecctionsFolder = ObjCreateInterface($pConecctionsFolder, $sIID_IShellFolder, $sTagIShellFolder)
        If IsObj($oConecctionsFolder) Then
            If SUCCEEDED($oConecctionsFolder.EnumObjects(Null, $SHCONTF_NONFOLDERS, $pEnumIDList)) Then
                $oEnumIDList = ObjCreateInterface($pEnumIDList, $sIID_IEnumIDList, $sTagIEnumIDList)
                If IsObj($oEnumIDList) Then
                    $tSTRRET = DllStructCreate($sTagSTRRET)
                    While (SUCCEEDED($oEnumIDList.Next(1, $pPIDLItem, $celtFetched)) And $celtFetched > 0)
                        If SUCCEEDED($oConecctionsFolder.GetDisplayNameOf($pPIDLItem, $SHGDN_NORMAL, DllStructGetPtr($tSTRRET))) Then
                            $twstring = DllStructCreate("wchar Name[512]", $tSTRRET.pOleStr)
                            If $twstring.Name = $sConnectionName Then
                                If $lnkPath = "" Then $lnkPath = @DesktopDir & "\" & $twstring.Name & ".lnk"
                                $bRet = CreateLnk($pPIDLConectionsFolder, $pPIDLItem, $lnkPath)
                                ExitLoop
                            EndIf
                            $twstring = 0
                        EndIf
                    WEnd
                EndIf
            EndIf
        EndIf
    EndIf

    If $pPIDLConectionsFolder Then _WinAPI_CoTaskMemFree($pPIDLConectionsFolder)

    Return $bRet

EndFunc   ;==>CreateNetWorkShortCut

Func CreateLnk($PIDL1, $PIDL2, $lnkPath)
    Local $oShellLink = 0
    Local $oIPersistFile = 0
    Local $pIPersistFile = 0
    Local $pAppendID = 0
    Local $bRet = False
    $oShellLink = ObjCreateInterface($CLSID_ShellLink, $sIID_IShellLinkW, $sTagIShellLink)
    If @error Then Return $bRet
    $pAppendID = ILAppendID($PIDL1, $PIDL2)
    If IsObj($oShellLink) And $pAppendID Then
        If SUCCEEDED($oShellLink.SetIDList($pAppendID)) Then
            $oShellLink.QueryInterface($sIID_IPersistFile, $pIPersistFile)
            $oIPersistFile = ObjCreateInterface($pIPersistFile, $sIID_IPersistFile, $sTagIPersistFile)
            If IsObj($oIPersistFile) Then
                $bRet = SUCCEEDED($oIPersistFile.Save($lnkPath, True))
            EndIf
        EndIf
    EndIf
    Return $bRet
EndFunc   ;==>CreateLnk


Func ILAppendID($PIDLIST_RELATIVE, $LPSHITEMID, $fAppend = True)
    Local $aRet = DllCall("Shell32.dll", "ptr", "ILAppendID", "ptr", $PIDLIST_RELATIVE, "ptr", $LPSHITEMID, "bool", $fAppend)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRet[0] = 0 Then Return SetError(10, $aRet[0], 0)
    Return $aRet[0]
EndFunc   ;==>ILAppendID


Func SHGetDesktopFolder()
    Local $aRet = DllCall("Shell32.dll", "long", "SHGetDesktopFolder", "ptr*", Null)
    If @error Then Return SetError(@error, @extended, 0)
    If $aRet[0] Then Return SetError(10, $aRet[0], 0)
    Return $aRet[1]
EndFunc   ;==>SHGetDesktopFolder


Func SUCCEEDED($hr)
    Return ($hr >= 0)
EndFunc   ;==>SUCCEEDED

Saludos

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By nacerbaaziz
      hello guys, please i need your help
      am trying to work with CreateWindowEx api, i created the window with it controls, also i setup the call back function
      i'am using WinMSGLoop to focus with the keyboard.
      here i have a problem, i hope that you can help me.
      on the controls i used the UDF that comme with the autoit, such as _GUIButton_Create, _GUIListBox_Create....
      but i can't find a STATIC control UDF, for that i used this

      local $h_ssrvlbl = _WinAPI_CreateWindowEx(0, "STATIC", "الخادم", BitOr($WS_VISIBLE, $WS_CHILD, $WS_CLIPSIBLINGS, $WS_CLIPCHILDREN), 250, 10, 100, 20, $hWnd)
      as you can see here, there is an arabic text, so here is the problem, the arabic text isn't show normally, what is the problem here?
      also i have  an other question about keyboard focus, when i used WinMSGLoop, it worked, but if i press alt+tab to switch windows or focus an other window and return back to my window, the focus of control is kill.
      can any one help me to solve that please?
      my code will be as file here with the include files
      i hope can any one help me here
      thanks in advance
       
      speed Test win.zip
    • By MarkBuchanan
      Hello,

      I am new to AutoIt so please bare with me. I am trying to write a script that installs a certain program on Win 10 and then based on a successful install create a file in a specific directory. Below is my install script which works, just not quite sure how to get it to write the file when its done. My thought is to add a "If FileExists" command at the end to make sure that the files are in the install folder and based on that write the file just not sure how to accomplish it. I hope that makes sense and thank you in advance for any help. 
       
      Local $Title="MobilePass Install"
      Local $FilePATH="\\XXXXXXX\XXXXXX"
      Local $UserName "*****8"
      Local $Password = "*******8"   ;Check if Application location already exists
      If FileExists ("C:\Program Files\WindowsApps\05EB1CFA.SafeNetMobilePASS_1.8.3.0_x64__bnm8hg3x9na9j") Then
      Exit
      Else
      Local $pid = RunAsWait ($UserName, $ComputerDomainName, $Password, 1, "MobilePASS+Setup_1.8.3.0_signed.exe", "", @SW_HIDE )
      Endif
       
    • By tarretarretarre
      Version 2.x.x and 3.x.x has been moved to branch 3.x
      About Autoit-Socket-IO
      Autoit-Socket-IO is a event driven TCP/IP wrapper heavily inspired from Socket.IO with focus on user friendliness and long term sustainability.
      I constantly want to make this UDF faster and better, so if you have any suggestions or questions (beginner and advanced) Do not hesitate to ask them, I will gladly help!
      Key features
      Simple API 99% data-type serialization thanks to Autoit-Serialize Can easily be extended with your own functionality thanks to Autoit-Events "Educational" examples Data encryption thanks to _<Crypt.au3> Limitations
      Speed. This UDF will sacrifice some speed for convenience Read more in the official thread
    • By nacerbaaziz
      question about _WinAPI_CreateWindowEx
      good morning
      welcome autoit team
      please i need your help
      i've searched a lot about how to use the _WinAPI_CreateWindowEx
      finally i found an example
      but i found some problem i hope you can help me
      firstly, i want to set the controls focussable with the keyboard input
      i already used the ws_tabStop but it did not work with me.
      secondly, i want to set some access keys linked with the window
      such as control+o enable the open button and control+f4 exit the app
      note: i need a local access keys and not a global hotkeys
      such as GUISetAccelerators
      finaly, before i will put the code here i must clarify a few things.
      1. you will ask me why you don't use the GUICreate function
      here i'll tell you that it as dialog and It is a little heavy in motion with screen readers.
      the screen readers for blind has some function that work with dialogs and others work with full windows style
      2. you will ask me why you didn't search the net for that?
      i will tell you that all examples that i found in the internet with pdfs and Picture books.
      i found some examples in microsoft but it with cpp.
      ok here is the code
      i hope you can help me to do what i want
      thank you in advance
       
      ; Small AutoIt Application that uses Windows API ; Written by Yuraj #NoTrayIcon #include <_RegisterClassEx.au3> #include <WinAPI.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <FontConstants.au3> AutoItSetOption("MustDeclareVars", 1) ; Window definitions Const $WinWidth = 370 Const $WinHeight = 350 Const $WinXPos = (@DesktopWidth / 2) - ($WinWidth / 2) Const $WinYPos = (@DesktopHeight / 2) - ($WinHeight / 2) Const $WinTitle = "Win32 Application - Text reader" Const $WinClass = "mainapp" Const $WinIcon = _WinAPI_LoadIcon(_WinAPI_GetModuleHandle("shell32.dll"), 13) ; Windows handles Global $hwnd, $edit1, $btn1, $btn2 ; Fonts Global $fnt1 ; Register class, Create the window Local $retVal = __WinAPI_RegisterClassEx($WinClass, "WindowCallback", $WinIcon, 0, _WinAPI_GetSysColor($COLOR_BTNFACE), BitOR($CS_DEFAULTSTYLE, $CS_DROPSHADOW)) ; If $retVal == 0 Then ; If registerclass fails MsgBox(16, "Error", "Error while registering window class!") Exit EndIf ; Create windows/controls $hwnd = _WinAPI_CreateWindowEx($WS_EX_STATICEDGE, $WinClass, $WinTitle, BitOR($WS_OVERLAPPED,$WS_SYSMENU, $WS_MINIMIZEBOX, $WS_GROUP, $WS_DLGFRAME), $WinXPos, $WinYPos, $WinWidth, $WinHeight, 0) $btn1 = _WinAPI_CreateWindowEx(0, "button", "Open file ...", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 25, 270, 100, 30,$hwnd) $btn2 = _WinAPI_CreateWindowEx(0, "Button", "Exit", BitOR($WS_VISIBLE, $WS_CHILD, $WS_TABSTOP, $WS_CLIPCHILDREN), 235, 270, 100, 30, $hwnd) $edit1 = _WinAPI_CreateWindowEx(0, "edit", "text", BitOR($WS_VISIBLE, $WS_CHILD, $WS_VSCROLL, $ES_AUTOVSCROLL, $es_readOnly, $WS_TABSTOP), 5, 5, $WinWidth - 15, $WinHeight - 100, $hwnd) ; Set controls identifiers _WinAPI_SetWindowLong($btn1,$GWL_ID,150) _WinAPI_SetWindowLong($btn2,$GWL_ID,160) ; Set (controls) fonts $fnt1 = _CreateFont("MS Sans Serif", 15) _WinAPI_SetFont($btn1, $fnt1) _WinAPI_SetFont($btn2, $fnt1) _WinAPI_SetFont($edit1, $fnt1) ; Set focus to edit _WinAPI_SetFocus($edit1) ; Show window _WinAPI_ShowWindow($hwnd) _WinAPI_UpdateWindow($hwnd) ; Main loop that keep application opened While 1 Sleep(100) WEnd ;=================================================================; ; WINDOW CALLBACK ... ;=================================================================; Func WindowCallback($_hwnd, $iMsg, $wParam, $lParam) Local $iNC, $iID Switch $iMsg ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_CLOSE ; Show message on closing If MsgBox(48 + 4, $WinTitle, "Do you want really exit?", 0, $hwnd) <> 6 Then Return 0 ; Call destructor and then exit main thread FinalizeApp() Exit ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Case $WM_COMMAND $iNC = _WinAPI_HiWord($wParam) $iID = _WinAPI_LoWord($lParam) Switch $iNC Case $BN_CLICKED ; When is control clicked Switch _WinAPI_GetDlgCtrlID($iID) Case _WinAPI_GetDlgCtrlID($btn1) BtnOpenFileClick() Case _WinAPI_GetDlgCtrlID($btn2) BtnExitClick() EndSwitch EndSwitch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EndSwitch Return _WinAPI_DefWindowProc($_hwnd, $iMsg, $wParam, $lParam) EndFunc ;==>WindowCallback Func FinalizeApp() _WinAPI_DeleteObject($fnt1) _WinAPI_DestroyWindow($hwnd) __WinAPI_UnregisterClass($WinClass) EndFunc ;==>FinalizeApp Func _CreateFont($fontName, $height = 16, $style = $FW_NORMAL, $italic = False, $underline = False, $strikeout = False) Local $hFont = _WinAPI_CreateFont($height, 0, 0, 0, $style, $italic, $underline, $strikeout, $DEFAULT_CHARSET, _ $OUT_DEFAULT_PRECIS, $CLIP_DEFAULT_PRECIS, $DEFAULT_QUALITY, $DEFAULT_PITCH, $fontName) Return $hFont EndFunc ;==>_CreateFont ;=================================================================; ; WINDOW EVENTS ;=================================================================; Func BtnOpenFileClick() Local $ret = _WinAPI_GetOpenFileName("", "Text files (*.txt)|All files (*.*)", ".", "", "", 1, 0, 0, $hwnd) If ($ret[0] > 0) Then Local $path = $ret[1] & "\" & $ret[2] Local $file = _WinAPI_CreateFile($path, 2, 2) Local $buf = DllStructCreate("byte[" & _WinAPI_GetFileSizeEx($file) & "]") Local $i = 0 _WinAPI_ReadFile($file, DllStructGetPtr($buf), _WinAPI_GetFileSizeEx($file), $i) ; Close file handle _WinAPI_CloseHandle($file) _WinAPI_SetWindowText($edit1, BinaryToString(DllStructGetData($buf, 1))) EndIf EndFunc ;==>BtnOpenFileClick Func BtnExitClick() FinalizeApp() Exit EndFunc ;==>BtnExitClick  
      _RegisterClassEx.au3
    • By nacerbaaziz
      hello sirs, please help me
      i tried to create a function that read a folder files to 3d array
      e.g
      $array[n][0][0] = ctName
      $array[n][0][1] = ctFilePath
      $array[n][0][2] = crtsections number
      $array[n][m][0] = KeyName
      $array[n][m][1] = KeyVal
      $array[n][m][2] = keySectionName
       
      that the array
      when i put one file into the folder all things work fine
      but when i put more than one file
      the last file worked fine but the others only the first key is showing
      please can you help me to correct this problem
      here is the example with the folder
      please accept my greetings
      and thanks in advance
       
      array3d.zip
×
×
  • Create New...