2

I need to run dnscrypt-proxy:
1. run automatically at startup or at my logon
2. windowless (not attached to cmd.exe)
3. as another user (not as my username)

If I use cmd.exe's runas, then dnscrypt-proxy.exe will also close when I close cmd.exe. It will not detach from cmd.exe:

runas /savecred /user:anotheruser "path-to\dnscrypt-proxy.exe"

Running dnscrypt-proxy.exe as a service will run it detached but how can I make it also run as another user?

I would like to use whatever programs that already come with Windows 10 Home rather than relying on third party software.

2 Answers2

1

I tried using cmd.exe's start and runas to no avail.
I tried using services.msc and taskschd.msc to no avail.

The only thing that worked was this PowerShell script. Place these lines into a .ps1 file in C:\Users\yourusername\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\filename.ps1 and will work as intended. (Probably C# would work too but I did not research it.)

$username = "otherusername"
$password = "password"

$credentials = New-Object System.Management.Automation.PSCredential -ArgumentList @($username,(ConvertTo-SecureString -String $password -AsPlainText -Force))

Set-Location "C:\Program Files\dnscrypt-proxy-win64"
Start-Process -FilePath ".\dnscrypt-proxy.exe" -Credential ($credentials) -ArgumentList "--resolver-name=dnscrypt.eu-dk
 --resolvers-list=dnscrypt-resolvers.csv" -WindowStyle Hidden

Start-Sleep -Seconds 5

if (Get-Process | Where-Object {$_.path -eq "C:\Program Files\dnscrypt-proxy-win64\dnscrypt-proxy.exe"})
{
    # program is running
} else {
    # program is NOT running
    New-Item -ItemType file -Path C:\Users\yourusername\Desktop\dnscrypt-proxy-failed-to-start.txt
}
0

You could try using the start command to run the runas command detached.

C:\start runas /savecred /user:anotheruser "path-to\dnscrypt-proxy.exe"

(here you can find some more information on the start command http://www.robvanderwoude.com/ntstart.php)

inaki
  • 168
  • 7
  • dnscrypt-proxy.exe is still executed attached to cmd.exe. When cmd.exe is closed, it closes too. Using `start ""` also is attached. – Milo Zelael Aug 31 '16 at 11:36
  • Maybe this can help? [link](http://superuser.com/questions/198525/how-can-i-execute-a-windows-command-line-in-background) – inaki Aug 31 '16 at 11:39