ur Posted December 15, 2016 Share Posted December 15, 2016 Whenever we try to access a network share it will prompt for credentials based on the shared folder settings. Like the below prompt Once you save them, they are saved in Windows Credentials of Credentials Manager in Control panel (run --> control keymgr.dll). But not able to found exact file or registry for this setting. So, can anyone suggest how to do this process of adding network credentials using AutoIT. Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 (edited) Easy... put a file .bat on C:\\ .... and execute it on windows load..."Autostart". This is an old trick Edited December 15, 2016 by rootx Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 1 hour ago, rootx said: Easy... put a file .bat on C:\\ .... and execute it on windows load..."Autostart". This is an old trick But what we need to keep in the batch file is the question then. Because I don't find any command line options to access the credential manager Link to comment Share on other sites More sharing options...
orbs Posted December 15, 2016 Share Posted December 15, 2016 cmdkey.exe Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 27 minutes ago, orbs said: cmdkey.exe Thank you very much. Don't know why it didn't came in Google search To add credentials.. cmdkey /add:sharedmachine /user:domainname\username /pass:password To remove credentials. cmdkey /delete:sharedmachine I will use them using run command to execute in my code. Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 34 minutes ago, ur said: But what we need to keep in the batch file is the question then. Because I don't find any command line options to access the credential manager First learn https://technet.microsoft.com/en-us/library/bb490717.aspx Second.... local user net use d:\\server\share /user:Dan password or net use d:\\server\share /user:Accounts\Dan password Domain net use d:\\server\share /user:DOMAIN\Dan password Then to have persistent add /persistent:yes Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 One more question. Is there any way to view these passwords?? Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 1 minute ago, ur said: One more question. Is there any way to view these passwords?? add swith /savecred Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 2 minutes ago, ur said: One more question. Is there any way to view these passwords?? ??what do you mean Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 3 minutes ago, rootx said: First learn https://technet.microsoft.com/en-us/library/bb490717.aspx Second.... local user net use d:\\server\share /user:Dan password or net use d:\\server\share /user:Accounts\Dan password Domain net use d:\\server\share /user:DOMAIN\Dan password Then to have persistent add /persistent:yes I am getting the below error when I try the net use System error 67 has occurred. The network name cannot be found. Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 What you wroted in the batch, and the 4 the last question pwd look at nirsoft Network Password Recovery. Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 net use \\servername\ /user:~\username password Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 (edited) net use Z: \\ipserver\ /user:\username password Edited December 15, 2016 by rootx Link to comment Share on other sites More sharing options...
ur Posted December 15, 2016 Author Share Posted December 15, 2016 3 minutes ago, rootx said: net use Z: \\ipserver\ /user:\username password ok..for mapping the network drives right.. But I need to access the network share directly as the number of shares are more than 26 The cmdkey is working.I am able to access the share once I add the credentials to credential manager. Link to comment Share on other sites More sharing options...
jguinch Posted December 15, 2016 Share Posted December 15, 2016 An AutoIt code answer (because it's a forum about AutoIt) : DriveMapAdd("", "\\ukreddy-e7470\c$", 0, "username", "password") JLogan3o13 1 Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 ok, try the normal cmd with Admin privilege.... net use \\ipserver\ this grant you to access to all shares Link to comment Share on other sites More sharing options...
rootx Posted December 15, 2016 Share Posted December 15, 2016 (edited) 4 minutes ago, jguinch said: An AutoIt code answer (because it's a forum about AutoIt) : DriveMapAdd("", "\\ukreddy-e7470\c$", 0, "username", "password") DriveMapAdd("", "\\ukreddy-e7470\c$", 1, "username", "password") persistent. and require #RequireAdmin Edited December 15, 2016 by rootx Link to comment Share on other sites More sharing options...
jguinch Posted December 15, 2016 Share Posted December 15, 2016 8 hours ago, rootx said: and require #RequireAdmin ??? Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Surf243 Posted December 15, 2016 Share Posted December 15, 2016 Hi ur, I prefer not to rely on external programs/tools so let me share an alternative approach to cmdkey.exe. I didn't write this, but I modified it to work for my needs. In my script I actually encrypt the password prior to storing it. Hopefully, this will make it easier for you. expandcollapse popup#include <Array.au3> $User = "user1" $Password = "password1" $AppName = "My App" $Comment = "Used For ABC" _Cred_Write($User, $Password) ; Write to Crediential Manager $aArray = _Cred_Read() ; Read from Crediential Manager _ArrayDisplay($aArray) _Cred_Delete() ; Delete Credientials Func _Cred_Write($User, $Password, $iPersist = 1, $Target = $AppName, $Comm = $Comment) ; iPersist ; SESSION = 1 ; LOCAL_MACHINE = 2 ; ENTERPRISE = 3 Local $Comment = DllStructCreate("wchar[100]") DllStructSetData($Comment, 1, $Comm) Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $userName = DllStructCreate("wchar[100]") DllStructSetData($userName, 1, $User) Local $credentialBlob = DllStructCreate("wchar[100]") DllStructSetData($credentialBlob, 1, $Password) Local $structCREDENTIAL = "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $NewCred = DllStructCreate($structCREDENTIAL) If @error Then MsgBox(0, "NewCred", "Error in DllStructCreate " & @error) ; Exit EndIf DllStructSetData($NewCred, "Flags", 0) DllStructSetData($NewCred, "Type", 1) DllStructSetData($NewCred, "TargetName", DllStructGetPtr($targetName)) DllStructSetData($NewCred, "Persist", $iPersist) DllStructSetData($NewCred, "AttributeCount", 0) DllStructSetData($NewCred, "UserName", DllStructGetPtr($userName)) DllStructSetData($NewCred, "CredentialBlob", DllStructGetPtr($credentialBlob)) DllStructSetData($NewCred, "CredintialBlobSize", StringLen($Password) * 2) DllStructSetData($NewCred, "Comment", DllStructGetPtr($Comment)) #comments-start MsgBox(0, "DllStruct", "Data:" & @CRLF & _ "Flags: " & DllStructGetData($NewCred, "Flags") & @CRLF & _ "Type: " & DllStructGetData($NewCred,"Type") & @CRLF & _ "TargetName: " & DllStructGetData($NewCred,"TargetName") & @CRLF & _ "Persist: " & DllStructGetData($NewCred,"Persist") & @CRLF & _ "AttributeCount: " & DllStructGetData($NewCred,"AttributeCount") & @CRLF & _ "UserName: " & DllStructGetData($NewCred,"UserName") & @CRLF & _ "CredentialBlob: " & DllStructGetData($NewCred,"CredentialBlob") & @CRLF & _ "CredintialBlobSize: " & DllStructGetData($NewCred,"CredintialBlobSize") & @CRLF & _ "Comment: " & DllStructGetData($NewCred,"Comment")) #comments-end Local $hAdvapi32 = DllOpen("Advapi32.dll") If @error Then MsgBox(0, "Error", "Cannot open Advapi32.dll") Exit EndIf Local $aRet = DllCall($hAdvapi32, 'bool', 'CredWriteW', 'ptr', DllStructGetPtr($NewCred), 'dword', 0) $NewCred = 0 EndFunc Func _Cred_Read($Target = $AppName) Local $aFuncRet[3] Local $iType = 1 ; 1 = Generic | 2 = Domain | 3 = Certificate Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") Local $aRet = DllCall($hAdvapi32, 'bool', 'CredReadW', 'ptr', DllStructGetPtr($targetName), 'dword', $iType, 'dword', 0, 'ptr*', 0) If $aRet[0] = 0 Then Return SetError(1, 0) Local $structCREDENTIAL = "" & _ "DWORD Flags;" & _ "DWORD Type;" & _ "Ptr TargetName;" & _ "Ptr Comment;" & _ "UINT64 LastWritten;" & _ "DWORD CredintialBlobSize;" & _ "Ptr CredentialBlob;" & _ "DWORD Persist;" & _ "DWORD AttributeCount;" & _ "Ptr Attributes;" & _ "Ptr TargetAlias;" & _ "Ptr Username" Local $tdata = DllStructCreate($structCREDENTIAL, $aRet[4]) Local $userName = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Username')) Local $sUser = DllStructGetData($userName, 1) Local $CredentialBlobSize = DllStructGetData($tdata, 'CredintialBlobSize') Local $credentialBlob = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'CredentialBlob')) Local $sPassword = StringLeft(DllStructGetData($credentialBlob, 1), $CredentialBlobSize / 2) Local $Comment = DllStructCreate("wchar[100]", DllStructGetData($tdata, 'Comment')) Local $sComm = DllStructGetData($Comment, 1) Dim $aFuncRet[] = [$sUser, $sPassword, $sComm] Return $aFuncRet EndFunc Func _Cred_Delete($Target = $AppName) Local $aRet Local $targetName = DllStructCreate("wchar[100]") DllStructSetData($targetName, 1, $Target) Local $hAdvapi32 = DllOpen("Advapi32.dll") $aRet = DllCall($hAdvapi32, 'bool', 'CredDeleteW', 'ptr', DllStructGetPtr($targetName), 'dword', 1, 'dword', 0) EndFunc Skysnake, spudw2k and Parsix 2 1 Link to comment Share on other sites More sharing options...
jguinch Posted December 15, 2016 Share Posted December 15, 2016 nice found @Surf243 : Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now