RDP from Powershell command-line - powershell

I'm having trouble creating a Powershell script that will open an RDP session without a prompt asking for a password.
I've followed the instructions in the following post, however the password prompt always pops up.
Here is the script:
cmdkey /generic:"server ip" /user:"username" /pass:"password"
mstsc /v:"server ip"
Does anyone know what I'm doing wrong? Is it possible to execute within the realm of Powershell? Thanks!

So I figured it out with Bonneau21's help (thanks!):
I'm connecting to a computer that isn't part of a domain, because of that I need to connect with a local user.
What I did was a slight change to the original script indicating that the user I need to connect with is local:
cmdkey /generic:"server ip" /user:"server ip\username" /pass:"password"

Related

PsExec connects using system name but not ipAddress

I need to use my local computer to simulate a test stand which will be on a domain and access a remote computer which is on a workgroup using PsExec. The testing computer is built from an imaging tool. The IP will be the same every time but the name isn't. The process I'm working with was used on an embedded XP system and is now being upgraded to WIN10. I've added network security using GPO and have found workarounds to be able to open the connection but for some reason just trying to run cmd on the remote machine does not work when using the IP, only the name. Using the IP returns the "access is denied" error. I have already added the token filter key to the registry. Has anyone heard of something like this before?
I have a script I'm trying to run but in the meantime I'm just trying to get
psexec \IP_ADDERESS -h -u USER_NAME(this is an admin) -p PASSWORD cmd
edit: I have to keep my computer on a domain but I have a spare that I was able to put on a workgroup with the test system. Running psexec went perfect. It makes no sense why it works for the name and not ip on a domain->workgroup connection and works exactly how I need it to on a workgroup->workgroup connection.

How can I mount a remote server just like raspbian does it?

I can manually connect to a remote server by going to the File Manager and select "Connect to Server" under the "Go" tab.
Then I can type in the ip and username and I am ready to go. And I dont need to add a password because I have set up ssh-keys.
As shown in the images below:
After that I can access the remote folder at this location:
/run/user/1000/gvfs/sftp:host=192.168.178.35,user=user/
My question is, how can I achieve the same result, but without the UI, just with the CLI?
(What command is used by the raspberry OS?)
And further, how can I unmount the volume after using it with the CLI?
Thanks for the help : )
You can simply type the following command in the console to connect to the remote server. When you are finished, you can close the connection with the command exit.
ssh username#address
You can find a very detailed description here.
So looking at the comment you wrote in the other answer, I think you're looking for an SFTP server, this is basically a server where you can manipulate directories and the files in them remotely by mounting it.
The image you showed however, does show an SSH server, as #flaxel said in his/her answer.

Cmdkey with empty password

I'm trying to start a remote desktop connection to a computer with a user that doesn't have a password, using Powershell. The cmdkey command does not seem to accept an empty password, but asks me for a password with a prompt.
I need to launch the remote desktop from a Powershell-script as it needs to connect to any of several computers at will, so saving the credentials to Remote desktop is not an option.
I have tried using stuff like "", $null, """", "^", ` but none of these work, they are either not a password at all, are the wrong password or just freeze the Powershell-script. The same exact code works just fine for an account that has a password on the same machine.
$username=
$IPAddress=
cmdkey /generic:$IPAddress /user:$username
mstsc /v:$IPAddress /admin
Start-Sleep -Seconds 1
cmdkey /delete:"LegacyGeneric:target=$IPAddress"
The script either asks for the password, or the remote desktop prompts for it, but then accepts just pressing "Ok" with an empty password, or the whole script freezes in some cases.
It should just connect as the empty password is correct.
Windows will not allow the logon over a network with a blank password. However, there is a registry setting you can do on the target machine that disables this behaviour:
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa]
"LimitBlankPasswordUse"=dword:00000000
A 'cleaner' way to set this is by using the Group Policy Editor (gpedit.msc) on the target machine.
Navigate to Computer Configuration -> Windows Settings -> Security Settings -> Local Policies -> Security Options and search for option Accounts: Limit local account use of blank passwords to console logon only
Double-click this option and check Disabled.
From then on, you should be able to remote log on to that computer with a blank password.
Note: this setting of course provides a security risk.
Read about Accounts: Limit local account use of blank passwords to console logon only

Alternatives for PsExec which works in standard user

I am using psexec to execute commands on remote server. Here is my command,
PsExec.exe" -u user \\server -h run.bat
I am entering the password manually. here I am using standard user account due to security issues. When I run the command I am getting the error,
"Make sure that the default admin$ share is enabled"
I read here that it cannot be done without admin privileges.
But when I test the same command in LAN it works in standard user.
How it works in LAN not in Remote server ?
Is there any alternative tools which will work in standard user ?
Please help me.
As an alternate tool, you can use Powershell and WinRM. Powershell allows you to execute a command, or an interactive session, on the remote windows server.
An example of executing a command is available here:
How to programmatically/remotely execute a program in EC2 Windows instance
If you need an interactive session, look at the Powershll command 'Enter-PSSession': https://technet.microsoft.com/en-us/library/hh849707.aspx

Logon failure in running a windows service

I am running a service called prunner on windows server 2012. I used the command sc to change the username and the password of the service:
sc.exe config myService obj= "sqa265\hero" password= "hero1"
The output of the command is saying that it have succeed but when I go to task manager in order to start the service I get: logon failure!!!
I tried to run the sc command under the user hero and under the user administrator but I still get the same error. But the very strange thing is that if I do the same thing manually via the task manager and service control pane I success and the service go to the state:running!!! But I need to automate this thing, so please any help?
You need to give the account "sqa265\hero" the SeServiceLogonRight permission. As you have noticed setting the credentials up through the control panel works, but what you might not have noticed is that if you tried to use the command line after using the control panel.
You can test this by setting the service back to the Local System account in the control panel, and then running your command-line again.
To fix this from a script, you can use the NTRights utility outlined in this MS knowledgebase article:
http://support.microsoft.com/kb/315276
After you install NTRights, you can run it like this:
NTRights.exe +r SeServiceLogonRight -u "sqa265\hero"
Combined with the sc config commandline you already have, the service should run with those credentials.
Further reading:
http://www.techrepublic.com/article/set-user-rights-using-the-ntrights-utility/5032903