ur

how to save credentials of network shares in windows

20 posts in this topic

Whenever we try to access a network share it will prompt for credentials based on the shared folder settings.

Like the below prompt

d1.PNG

d2.PNG

Once you save them, they are saved in Windows Credentials of Credentials Manager in Control panel (run --> control keymgr.dll).

d3.PNG

 

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.

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Easy... put a file .bat on C:\\ .... and execute it on windows load..."Autostart". This is an old trick

Edited by rootx

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
27 minutes ago, orbs said:

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

One more question.

Is there any way to view these passwords??

Share this post


Link to post
Share on other sites
1 minute ago, ur said:

One more question.

Is there any way to view these passwords??

add swith /savecred

Share this post


Link to post
Share on other sites
2 minutes ago, ur said:

One more question.

Is there any way to view these passwords??

??what do you mean

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

What you wroted in the batch, and the 4 the last question pwd look at nirsoft Network Password Recovery.

Share this post


Link to post
Share on other sites

net use \\servername\ /user:~\username password

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

net use Z: \\ipserver\ /user:\username password

Edited by rootx

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

ok, try the normal cmd with Admin privilege....  net use \\ipserver\ this grant you to access to all shares

Share this post


Link to post
Share on other sites

#17 ·  Posted (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 by rootx

Share this post


Link to post
Share on other sites

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.

 

#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

 

2 people like this

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

  • Similar Content

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      i am working on a application where if the flashing is success i get a window saying "SUCCESS" and if the flashing failed a window saying "FAILED" and i have to automatically identify pass or fail.the problem is both the windows are having the same control ID. how can i differentiate between both windows? so that i can make use of that in script for automation///
       
       
      Thanks
    • comtech80
      By comtech80
      Folks,
      I have an issue I've been trying to solve for a while, I'm trying to add static routes in DHCP via a 121 route rule in Windows 2012 R2 is a brutal manual process and wanted to automate this via AutoIT.
       
      When I use the "ControlGetText" everything displays properly in the MSG box but when I try and use "ControlSetText" or "ControlSend" the values won't display in the input box but the action comes back as successful?
      Anyone able to help me with this? I'm thinking this might be an active window issue but i'm not sure.
      Here is a part of my code.
       
      $hWnd = WinWait("[TITLE:Add a Static Route]","", 10)
      WinActivate($hWnd)
      $Status = ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:4]", "192"); Does not add 192 to the text box.
      Local $sTextEdit1 = ControlGetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]")
      ConsoleWrite ( "ControlSend Status: " &  $Status & @CRLF); Returns a Value of 1
      ConsoleWrite ( "ControlGetText Value Edit1: " &  $sTextEdit1 & @CRLF);
       
      Please see attachment for more info.

    • lganta
      By lganta
      Hello!
      I created some scripts for a simple farming bot a few years ago and they rely on ControlSend.
      A year ago I quit that game and then installed Windows 10 (was using windows 7).
      Recently I installed that game and tried running them again and they seem to work (I have some messages displayed on the screen with the state of the bot ), except for the ControlSend part (which obviously is crucial).
      I started debugging the scripts so I created a basic script that makes use of Send. I tested this with Notepad in focus and works just fine and then with my game window in focus and it didn't work (it's supposed to write that text in an input box from the game).
      #include <MsgBoxConstants.au3> Sleep(3000); Send("some text"); MsgBox($MB_OK, "Notification", "Control was sent!");  
      Is there a way for the creators of the game to create some kind of security system against this? Or something happens because I updated to Windows 10?
      Is there something I'm missing?
      Thank you!
    • badcoder123
      By badcoder123
      Anyone know how to access the information circled in the photo?
       

    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me