[英]Using 'runas' command and check which USER/DOMAIN the current session is on
我經常使用具有多個域帳戶的runas
運行cmd
shell,如何從在不同域帳戶下運行的 shell 獲取域名?
例子:
C:\>echo %userdomain%
DOMAIN1
C:\>runas /netonly /user:DOMAIN2\USER cmd
Enter the password for DOMAIN2\USER:
Attempting to start cmd as user "DOMAIN2\USER" ...
現在在以DOMAIN2\USER
運行的新 shell 上仍然給我%userdomain%
output 作為DOMAIN1
。 有沒有辦法獲得runas
帳戶的域?
誰是我.exe
for /f "delims=\" %a in ('whoami') do @echo.%a
這是與/netonly參數一起使用時RunAs的預期行為。
使用/netonly允許您與您的用戶 (DOMAIN1\USER) 一起運行命令/應用程序/shell,同時通過網絡與另一個用戶 (DOMAIN2\USER) 進行身份驗證。
來自微軟文檔:
/netonly表示指定的用戶信息僅用於遠程訪問。 此參數不能與 /profile 參數一起使用。
但是,您可以使用將設置變量的命令打開新的 cmd.exe 提示符,然后您可以使用...例如:
runas /netonly /user:DOMAIN2\USER "cmd /K SET NETONLYUSER=DOMAIN2\USER"
因此,您可以使用%NETONLYUSER%在新的 cmd.exe 中訪問此變量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.