जवाबों:
Win32_LogonSession Win32_LogonSession वर्ग, लॉगऑन टाइप देखें ।
Logntype.cmd:
@ECHO OFF
@FOR /F "tokens=4 delims==" %%L IN ('wmic path win32_loggedonuser^|find /I "%username%"') do @SET /A LogonId=%%L
@echo LogonId=%LogonId%
@FOR /F %%T IN ('wmic path win32_logonsession Where ^(LogonId^=%LogonId%^) get LogonType^|more /E +1') do @SET /A LogonType=%%T &GOTO SkipLineLogonType
@:SkipLineLogonType
@echo LogonType=%LogonType%
@IF %LogonType% EQU 2 (
@ECHO Interactive
:: Interactive Code!
) ELSE (
@ECHO Your Code!
:: not interactive logon
)
अनुकरण का मामला:
@IF %LogonType% EQU 2 (
@ECHO Interactive
@ECHO Interactive Code!
)
@IF %LogonType% EQU 7 (
@ECHO Interactive
@ECHO Interactive Code!
)
संख्यात्मक मान जो लॉगऑन सत्र के प्रकार को इंगित करता है:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: LogonType :
::
:: Value Meaning
::
:: 0 Used only by the System account.
::
:: Interactive
:: 2 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.
::
:: Network
:: 3 Intended for high-performance servers to authenticate clear text passwords. LogonUser does not cache credentials for this logon type.
::
:: Batch
:: 4 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.
::
:: Service
:: 5 Indicates a service-type logon. The account provided must have the service privilege enabled.
::
:: Proxy
:: 6 Indicates a proxy-type logon.
::
:: Unlock
:: 7 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.
::
:: NetworkCleartext
:: 8 Windows Server 2003, Windows 2000, and Windows XP: 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.
::
:: NewCredentials
:: 9 Windows Server 2003, Windows 2000, and Windows XP: 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.
::
:: RemoteInteractive
:: 10 Terminal Services session that is both remote and interactive.
::
:: CachedInteractive
:: 11 Attempt cached credentials without accessing the network.
::
:: CachedRemoteInteractive
:: 12 Same as RemoteInteractive. This is used for internal auditing.
::
:: CachedUnlock
:: 13 Workstation logon.
::
त्वरित और गंदा समाधान:
एक उचित रूप से संरक्षित फ़ोल्डर ढूंढें जिसमें एक "वर्कस्टेशन लॉक फ़ाइल" बनाई जा सकती है जो अन्य .bat फाइलें अस्तित्व की जांच कर सकती हैं।
createLockFile.bat
निम्नलिखित कोड वाले इस फ़ोल्डर में एक फ़ाइल बनाएँ :
@echo off
@echo "" > WORKSTATION_IS_LOCKED
deleteLockFile.bat
निम्नलिखित कोड वाले इस फ़ोल्डर में एक और फ़ाइल बनाएँ :
@echo off
del WORKSTATION_IS_LOCKED 2>nul
एक कार्य बनाएं जो चलाने के लिए कार्य केंद्र लॉक पर ट्रिगर हो createLockFile.bat
और एक अन्य कार्य जो ट्रिगर पर कार्य केंद्र को चलाता है deleteLockFile.bat
। Start in:
मान को युक्त फ़ोल्डर के पथ पर सेट करना सुनिश्चित करें ।
अब आप किसी भी अनुसूचित .bat फ़ाइल के शीर्ष पर निम्न कोड का उपयोग कर सकते हैं यदि वर्कस्टेशन बंद है तो जल्दी से बाहर निकलें:
if exist "<containing folder path>\WORKSTATION_IS_LOCKED" (
exit /b
)
अनुमति देने के लिए यहां देखें .bat फाइलें "अदृश्य रूप से" निष्पादित करने के लिए (यानी, बिना खिड़की के संक्षिप्त रूप से दिखाई दें)