Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows 10

รันโปรแกรมเป็นผู้ใช้อื่น (RunAs) ใน Windows 10: วิธีครบถ้วน

Windows 10 รองรับการรันแอปพลิเคชันในฐานะผู้ใช้อื่น (Run As Different User) ในเซสชันปัจจุบัน ซึ่งช่วยให้รันสคริป्ट (.bat, .cmd, .vbs, .ps1), ไฟล์ 실행 (.exe) หรือติดตั้งโปรแกรม (.msi, .cab) ด้วยสิทธิ์ผู้ใช้อื่น (มักเป็น Admin) ได้

รันจาก File Explorer (GUI)

  1. หาไฟล์หรือ Shortcut ที่ต้องการรัน
  2. กดปุ่ม Shift ค้าง + คลิกขวา
  3. เลือก Run as different user
  4. กรอก Username และ Password (รูปแบบ Domain: Domain\User หรือ User@Domain)
  5. กด OK — โปรแกรมจะรันภายใต้บัญชีนั้น

หมายเหตุ: หากไม่見 "Run as different user" ให้ตรวจสอบ Group Policy: gpedit.msc > Computer Configuration > Administrative Templates > Windows Components > Credential User Interface > Require trusted path for credential entry = Disabled/Not Configured

ใช้คำสั่ง RunAs.exe จาก Command Prompt

runas /user:admin "C:\Windows\notepad.exe"
runas /user:"antony jr" notepad.exe
runas /user:corp\server_admin "notepad.exe C:\ps\region.txt"
runas /netonly /user:contoso\bmorgan cmd.exe

พารามิเตอร์สำคัญ:

  • /noprofile – ไม่โหลด User Profile (เร็วขึ้น แต่อาจทำให้บางโปรแกรมทำงานผิด)
  • /savecred – บันทึกรหัสผ่านใน Credential Manager (ไม่แนะนำให้ใช้กับบัญชี Admin เนื่องจากความปลอดภัย)

สร้าง Shortcut สำหรับ Run As Different User

  1. คลิกขวา Desktop > New > Shortcut
  2. พิมพ์คำสั่ง: runas /user:admin /savecred "C:\Windows\cmd.exe"
  3. ตั้งชื่อ Shortcut
  4. ครั้งแรกจะถามรหัสผ่าน ครั้งต่อไปจะใช้ Credential ที่บันทึกไว้

รัน MMC Snap-ins เป็นผู้ใช้อื่น

runas.exe /user:DOMAIN\USER "cmd /c start \"\" mmc %SystemRoot%\system32\dsa.msc"

เปลี่ยน dsa.msc เป็น snap-in อื่นๆ เช่น compmgmt.msc, gpmc.msc เป็นต้น

เพิ่มเมนู "Run as different user" ใน Start Menu

  1. เปิด gpedit.msc
  2. ไป User Configuration > Administrative Templates > Start Menu and Taskbar
  3. Enable Show Run as different user command on Start
  4. หรือเพิ่ม Registry: HKCU\Software\Policies\Microsoft\Windows\Explorer\ShowRunasDifferentuserinStart = 1 (DWORD)
  5. รัน gpupdate /force

ข้อกำหนดเบื้องต้น

  • บริการ Secondary Logon (seclogon) ต้องทำงานอยู่ (Get-Service seclogon)
  • บัญชีเป้าหมายต้องมีรหัสผ่าน (Empty password ไม่ทำงาน)