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 t0nZ
      Hi to all, I was wondering how to do something like this powershell command:
      Get-NetConnectionProfile -InterfaceAlias "Ethernet" | Set-NetConnectionProfile -NetworkCategory Private -Confirm:$false -PassThru natively, or bypassing powershell, in AutoIt.
      My goal is to change the state of the current network connection from public to private and viceversa.
      And looking beyond, to enable/disable network discovery, network crypt properties, sharing options etc....
       
    • By mLipok
      I want to present BETA Version of my ADO.au3 UDF.
      This is modifed version of _sql.au3 UDF.
       
      For that I want to thanks : ; Chris Lambert, eltorro, Elias Assad Neto, CarlH
       
      This is first public release , and still is as BETA
       
       
      DOWNLOAD LINK (in download section): 
       
       
      Have fun,
      mLipok
       
       
      EDIT: 2016-06-03
      Below some interesting topics about databases:
       
       
      EDIT 2016/07/04:
      For more info about ADO look here:
      https://www.autoitscript.com/wiki/ADO
      FOR EXAMPLE DATABASE use AdventureWorksDW2016_EXT.bak from:
      https://github.com/microsoft/sql-server-samples/releases/download/adventureworks/AdventureWorksDW2016_EXT.bak
      I will relay on this database in my examples.
       
      Here is link to post which shows how "ODBC Data Source Administrator" looks like.
       
    • 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
×
×
  • Create New...