RUNAS

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
milend1966
Posts: 7
Last visit: Tue Feb 28, 2012 2:37 am

RUNAS

Post by milend1966 »

Hi, i need to run a vbs script at logon with scheduled task and the task run as administrator user . These script run at logon of any users and write to a file USERNAME, PCNAME and DATE. The problem is that using task scheduer the record in the file is always with USERNAME parameter as Administrator. How can i run these task registering as USERNAME the real logon username?I used the objNetwork.Username but it doesn't work...it always write Administrator as USERNAME...Thanks
User avatar
milend1966
Posts: 7
Last visit: Tue Feb 28, 2012 2:37 am

RUNAS

Post by milend1966 »

Thanks. I need that the file vbs and login.txt can only modified by one user because it contain login information and no other users can modify the information inside file...
User avatar
milend1966
Posts: 7
Last visit: Tue Feb 28, 2012 2:37 am

RUNAS

Post by milend1966 »

Sorry, maybe my description was not very clear..I need to run a vbs script as administrator but this file register the logon information on a TXT file(logon.txt): the user that is logged on pC, the computer NAME and the date. If i run this script as administrator with task scheduler on the logon.txt file i always have administrator as username and it seems that only administator is able to logon on this computer. My vbs file contain:Const ForReading = 1Const ForWriting = 2Const ForAppending = 8set objNetwork = createobject("wscript.network")Set objComputer = CreateObject("WScript.Network")Dim DataCorrente Dim DataFormattataDataCorrente = NowDataFor = DatePart("d",DataCorrente) & "/" & DatePart("m",DataCorrente) & "/" & DatePart("yyyy",DataCorrente)Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("C:Scripttest.txt", ForReading)Do Until objFile.AtEndOfStreamlinea = objFile.Line'WScript.echo "Linea "&linea strLine = objFile.ReadLine arrServiceList = Split(strLine , ",")dominio = LCase(objNetwork.Userdomain)utente = LCase(objNetwork.Username)account = dominio&""&utente'WScript.echo "account è :"&account strContents = LCase(objComputer.ComputerName)&","&dominio&","&utente&","&dataforAs i said objNetwork.Username give back always administrator as value. Do you know other method to have back the user that is really logged on computer and not administrator , that is the runas user of task scheduler ?
User avatar
milend1966
Posts: 7
Last visit: Tue Feb 28, 2012 2:37 am

RUNAS

Post by milend1966 »

Ok, thank you !
This topic is 12 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked