开发者

Create process as user in ruby

开发者 https://www.devze.com 2022-12-10 09:27 出处:网络
The following code is in a file called run.rb, the idea is to run ruby as a different user so I can do some testing.

The following code is in a file called run.rb, the idea is to run ruby as a different user so I can do some testing.

require 'rubygems'
require 'win32/process'

domain = 'WORLDWIDE'
user_name = 'user'
password = 'password'
rubyScript = 'ruby test.rb'
Process.create(:command_line => rubyScript, :domain => domain, :with_logon => user_name, :password => password, :close_handles => false)

the contents of test.rb is:

require 'rubygems'
require 'watir'

browser = Watir::IE.ne开发者_运维问答w
browser.goto('http://localhost:44001/Users/List')
puts browser.text

when I run 'ruby run.rb' a command shell opens and then closes straight away. Any ideas what I am doing wrong here?


Reviving a dead question, but in Windows NT, other users can't interact with your desktop. So if you're logged on as DOMAIN\user1 and spawn a process as DOMAIN\user2, the DOMAIN\user2 process cannot interact with DOMAIN\user1's desktop. An exception to this is if the process is running as a service and has the "Can interact with desktop" box checked in the service properties (but I think that requires that it run as SYSTEM).

It is possible to use the Local Security Policy (secpol.msc) to assign user rights to that user that permits that user to interact with everyone's desktops, but that would be unsafe to do if the user is granted the right to logon interactively.


It's probably running your command just fine, opening a new command window (since it's a new windows Process), then closing that window when it completes. Try throwing a "sleep 1000" at the end of test.rb. If I'm correct, that should keep the window around so that you can view the output.

0

精彩评论

暂无评论...
验证码 换一张
取 消