程序使用任务调度程序,以管理员身份运行echos用户

时间:2016-02-06 08:42:18

标签: batch-file echo

我正在尝试创建一个回显当前用户的程序。

由于程序需要使用任务计划程序以管理员身份运行,因此%username%始终返回admin,而不是用户。

我最终想要的是每次用户登录,关闭,锁定,解锁,切换用户时,回显时间戳,用户信息和电脑信息的批次......

2 个答案:

答案 0 :(得分:0)

之前我遇到过类似的问题,尝试使用whoami

答案 1 :(得分:0)

当前用户是IS管理员。 Windows支持多个用户(尽管一次只有一个用户)。您可以做的是查询登录的用户并选择交互式用户。

潜在用户名单

wmic PATH Win32_SystemUsers get /format:List
wmic PATH WIN32_UserAccount get /format:List
wmic PATH WIN32_Account get /format:List

所有登录的用户都包含系统帐户。 NB管理员将有两个登录 - 一个是有限用户,另一个是提升。

wmic PATH Win32_LoggedOnUser get /format:List

查找有关登录类型的信息

wmic PATH Win32_LogonSession get /format:list

登录类型列表 - 您想要2。

LogonTypeData type: uint32Access type: Read-only


Numeric value that indicates the type of logon session.



Value

Meaning

0 
Used only by the System account.

 Interactive2 
Intended for users who are interactively using the machine, such as a user being logged on by a terminal server, remote shell, or similar process.

 Network3 
Intended for high-performance servers to authenticate clear text passwords. LogonUser does not cache credentials for this logon type.

 Batch4 
Intended for batch servers, where processes can be executed on behalf of a user without their direct intervention; or for higher performance servers that process many clear-text authentication attempts at a time, such as mail or web servers. LogonUser does not cache credentials for this logon type.

 Service5 
Indicates a service-type logon. The account provided must have the service privilege enabled.

 Proxy6 
Indicates a proxy-type logon.

 Unlock7 
This logon type is intended for GINA DLLs logging on users who are interactively using the machine. This logon type allows a unique audit record to be generated that shows when the workstation was unlocked. 

 NetworkCleartext8 
Preserves the name and password in the authentication packages, allowing the server to make connections to other network servers while impersonating the client. This allows a server to accept clear text credentials from a client, call LogonUser, verify that the user can access the system across the network, and still communicate with other servers.

 NewCredentials9 
Allows the caller to clone its current token and specify new credentials for outbound connections. The new logon session has the same local identify, but uses different credentials for other network connections.

 RemoteInteractive10 
Terminal Services session that is both remote and interactive.

 CachedInteractive11 
Attempt cached credentials without accessing the network.

 CachedRemoteInteractive12