Jump to content
ur

how to save credentials of network shares in windows

Recommended Posts

ur

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
rootx

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
ur
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
ur
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
rootx
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
ur

One more question.

Is there any way to view these passwords??

Share this post


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

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
ur

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

Share this post


Link to post
Share on other sites
rootx

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

Edited by rootx

Share this post


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

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
rootx
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
Surf243

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

 

  • Like 2

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

    • VITSUSA
      By VITSUSA
      I am using window XP in my desktop, so I want to convert basic disk to a dynamic disk, so how it is possible?
    • simy8891
      By simy8891
      Hi guys,
      It's been a while since I wrote my last message here and a while since I used AutoIt. I'm currently sort of desperate and I'm trying to find some help in regards of getting the network usage per process!
      I'm not interested in the total network usage of the NIC, but only on a specific PID's network utilization. They idea is to collect the amount of traffic uploaded and downloaded by a list of specific processes. So far Process Hacker and Process Explorer are capable of getting what I need, but I need to use these numbers in another script so they're sort of useless to me. I can't seem to find a way around it.
      Any idea, help is greatly appreciated.
      Thanks
    • XaelloNegative
      By XaelloNegative
      Hi,
      I'm currently saving process time stamps of my employer's other employees and saving it in a text document as data storage. However, my employer wants it to be processed in a day to day basis to generate their average process time per day. How can I compare today from yesterday and so on and so forth with the succeeding days? Whats the best approach to this?
      Thank you.
      ~XN~
    • mdwerne
      By mdwerne
      Hello,
      I'm working on a script that writes detailed application event logs, and I'd like to know if there is a way with Autoit to write multiple lines of XML EventData (see example below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike</Data> <Data>Observer Username: Miguel</Data> etc... </EventData> </Event> So far, using EventCreate, everything I send end's up in a single <data> entry (see below):
      <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Application" /> <EventID Qualifiers="0">1001</EventID> <Level>4</Level> <Task>0</Task> <Keywords>0x80000000000000</Keywords> <TimeCreated SystemTime="2015-07-12T21:26:07.000000000Z" /> <EventRecordID>86554</EventRecordID> <Channel>Application</Channel> <Computer>YOUR_COMPUTER</Computer> <Security /> </System> <EventData> <Data>DeskTop Agent: Mike Observer Username: Miguel</Data> </EventData> </Event> Here is the code I'm using thus far (which does not work the way I'd like):
      $LogData = @CRLF & "DeskTop Agent: " & @UserName & @CRLF & "Observer Username: " & $DTObserver & @CRLF & "File name/s with extension: " & $FilenameWextension & @CRLF & "Action Performed: " & $ActionPerformed & @CRLF & "Explanation: " & $Explanation & @CRLF & "Machine Name: " & @ComputerName & @CRLF & "IP Address: " & @IPAddress1 & @CRLF & "App1Installed: " & $App1 & @CRLF & "App2Installed: " & $App2 Run("eventcreate /T Information /ID 100 /L Application /SO DTALog /D " & Chr(34) & "DTALog Details: " & $LogData & Chr(34), "", @SW_HIDE, 2) I found a Stackoverflow post that talks about doing it in C# (https://stackoverflow.com/questions/7694276/how-to-add-multiple-lines-of-eventdata-to-an-eventlog-in-windows)
      but I'd like to determine if it can be accomplished with AutoIt!.
      Thanks for your time,
      -Mike
    • 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
×