How to run as different user without prompting user batch - authentication

I have a batch file that runs another batch file as a different user.
I also need to run the calling batch file remotely. Locally I can bypass having to enter the password with the /savecred option but then when I run the batch remotley, I still get prompted for the password but it would appear the connection times out because I'm brought back to the powershell prompt on the machine i'm connecting from.
my batch looks like this:
runas.exe /env /savecred /user:sqlsvr_dba ".\myBatch.bat"
How can I run the remote batch on my local machine without having to enter the password? I've been trying to use powershell for this.

Same question bothered me too :-)
I've tried to workaround this with schtasks and eventcreate.Here i posted my solution :
http://ss64.org/viewtopic.php?id=1539
If you want to run the script on a remote machine you can also try with wmic:
http://ss64.org/viewtopic.php?id=1495
Hope these will help you.

Related

Testing if user created in AD can be logged into on a VM

I am a QA automation engineer and in the web app I test there's a feature that creates Active Directory users.
My tools are - Selenium (Java), RemoteWebDriver, Selenium Grid (Docker)
I was trying to find ways to validate this process and came to a stop - this field (AD) is new
to me and I need to find a way to make sure the user was created and can be logged into in the
network.
I was trying to find a way to do this and came up with 2 options, where the first one is the least
preferred way:
Make a request (API? 3rd side tool?) to get the relevant user(s).
The issue:
A user created and registered in the AD doesn't necessarily mean that the client can log into it (at least by the way I understood how AD works), and so it loses the most important consequence of the feature.
Use a VM, get the AD user information (username + password: possible) and try to log into the VM using those details.
The issue:
I haven't came across a tool that does it, the closest thing is Robot class or WinAppDriver.
WinAppDriver seems like the best solution as of now although I don't know how to make the login process work since it's the process starts before the desktop is open and I don't know how to locate the username and password field, so I figured using Robot class seems like the simplest solution, if it works on a VM that is, which as of now doesn't seem like it does.
So, before advancing on learning how to use WinAppDriver with my current automation, I'd like and appreciate your opinions about the matter or if you have simpler solutions.
Thank you very much for reading!
• We can check whether a user is created successfully or not and if that user can log in to the AD domain or not by executing a script as below. It is a powershell script that auto logs in through remote desktop protocol in the other domain joined VM from an Azure domain joined VM that checks whether the recently created user can login or not.
Powershell script : -
cmdkey /list | ForEach-Object{if($_ -like "*target=TERMSRV/*"){cmdkey /del:($_ -replace " ","" -replace "Target:","")}}
echo "Connecting to 192.168.1.100"
$Server="192.168.1.100"
$User="Administrator"
$Password="AdminPassword"
cmdkey /generic:TERMSRV/$Server /user:$User /pass:$Password
mstsc /v:$Server
• In the above script, replace the ‘$user’ value by the user principal name of the newly created user, i.e., ‘$User=”testdemo#example.com”’ and the ‘$Password’ value by the password set for that user. Also, ensure that you replace and enter the correct IP address of the domain controller/AD server. Also, ensure that before executing the above powershell script, execute the below commands in an elevated (administrator privileges) powershell console.
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Lastly, please ensure that while creating the user, the option ‘User must change password at next logon’, ‘Account is Disabled’, ‘Password never expires’ and ‘User cannot change password’ are unchecked and not selected.
• Also, you can use the below command line script for logging in to the domain joined Azure VM through RDP protocol. In the below command, replace the ‘username’ and ‘password’ with the username and password of the user created recently to log in to the Azure VM with this command line script. Also, replace the ‘TERMSRC’ with the hostname of the server system or the domain joined VM where the specified UNC path is located and replace the ‘some_unc_path’ with the actual path UNC path of the shared directory folder. Please execute the below command through elevated (administrator privileges) command prompt.
Command script: -
c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -nolog -command cmdkey /generic:TERMSRC/some_unc_path /user:username /pass:pa$$word; mstsc /v:some_unc_path

Error in execute process task while uploading a file to sftp server using PSFTP.exe

I created a execute process task in SSIS to upload a file to a sftp server. I have full access to the server folder and was able to drag and drop files using filezilla. I am using putty sftp client psftp.exe to do the upload. Now when I use the psftp.exe with user and pass and batch arguments, it works perfectly fine in windows cmd. But when I execute the same in SSIS, I get the following error:
Error: 0xC0029151 at Execute Process Task, Execute Process Task: In Executing "C:\temp\psftp.exe" "user -pw pass -be -batch -b Upload.bat" at "C:\temp", The process exit code was "1" while the expected was "0".
Task failed: Execute Process Task
My windows cmd arguments are :
psftp.exe devsftp#secftp2.alliedpilots.org -b UploadUsersToSftp.bat
and then it asks for password and after entering password, file upload is done successfully. But I am having trouble performing same through SSIS. Below is the SSIS process task argument screenshot:
I searched online and found some similar questions at here but nothing specific to psftp. Also found same question on stackoverflow here but the solution mentioned is permissions, which I already checked.
Any help would be appreciated.
The SSIS most probably runs under a different local account than the one you use in "Windows cmd".
An SFTP access requires confirmation of a host key. You have probably verified the host key in your local account in the past, so it is cached in Windows registry.
But the account that runs SSIS does not have the host key cached. So it must fail.
You should add -hostkey switch to psftp.exe command line with the fingerprint of the expected host key.
If that does not help, wrap the psftp.exe to a batch file and redirect its output to a file.
psftp.exe devsftp#secftp2.alliedpilots.org -b UploadUsersToSftp.bat > c:\temp\psftp.out 2>&1
And run the batch file in SSIS, instead of psftp.exe directly.
Then check the file for errors.

echoid.exe remote execution issue (wrong Locking Code output)

I am trying to bring locking code of a farm in automatic way.
So, i have on each remote server echoid.exe and a batch file.
The batch file simply execute the echoid.exe and write its output into a text file which i can parse.
The problem is when im triggering the .bat file remotely, it seems like the echoid.exe executed on the container host (the one im using to send execution command through psexec for example) rather than executing the code in the remote host (meaning- the locking code output is wrong) . If the same .bat file executed locally (and manually), the results are OK.
Any idea why? does anyone know how can i run the echoid remotely and get the correct results?
i have tried several remote action and all failed and brought wrong results :(
please help!
BTW all remote machines are WIN OS.

How to input password on command prompt using VBA?

I've created a procedure on VBA (Excel) that restarts services on remote servers calling the command prompt and executing the "runas" command. I need to enter the command on the servers as administrator. So far it works fine but I don't want to have to type my password for each I want to run the command in. I know how I can automate the task using VBA and the Excel. What I don't know is how could I input my password on the command prompt using VBA?
Can anybody help me?
Thanks.
I've had all sorts of issues trying to convince runas to let me specify passwords from a program.
In the end, I tossed it and downloaded psexec from the Microsoft Windows Sysinternals site, which has other good stuff as well.
While many see this as a tool running remote programs, it can also be used quite happily to run local stuff under a different user name while allowing you to specify the password as a command-line argument, such as:
psexec -d -u USER -p PWD -w WORKDIR EXECUTABLE
You should be able to create a textbox control in VBA with the input mask set to password, this will allow you to enter the password in a non-viewable fashion.
Then you can just construct the psexec command and execute it from VBA, without having to worry about injecting the password into the process running runas.

Remotely control a graphical vb.net program through a command prompt

I have created a VB.NET program using windows forms. The program runs on a remote PC and displays information on a screen. The computer does not even have a mouse or keyboard connected to it. The program shows the information based on the file that is loaded.
I want to be able to change this file remotely to another file that is already on the remote PC. I can't use a graphical remote desktop client as we have very limited bandwidth.
So, my idea is to change the file using the command prompt (I think I'll need something like SSH). I'm not sure how to do this. Should I use something like this and load DosModule first:
Module DOSModule
Public Sub Main()
Console.Write("First, start with Command Prompt processing ...")
Dim myWinForm As New WinForm
Application.Run(myWinForm)
End Sub
End Module
How would I then read commands that is send to the program? I also only want one instance of the program running.
Thanks
You have 2 options. The first is a custom program that WILL require some network programming, like it or not. I would suggest creating either a Command-Line batch file or else a PowerShell script, then creating a program to transfer the script to the remote computer and execute the script.
The second option and the one better suited for you would be to download an SSH server. An SSH server will essentially open a command window and pipe the input and output over to a telnet client running on your machine. If you are running a version of Windows Server, an SSH server comes with Windows Server. Otherwise, you can download one for free here: http://www.freesshd.com/
Once you install the SSH server, you simply use telnet, from a command prompt, to link up with your remote SSH server