Kasper Katzmann
asked on
Adding data to MS access database
I have this script that shows a users username and computername. Instead of showing the information, I would like to write it to an Access database. But unfortunately I have no idea about how to solve it.
It is supposed to be run from a login-script, so if another approch is preferable I am listening :-)
I hope someone can help.
----- EXISTING SCRIPT -----
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo ")
arruName = Split(objSysInfo.UserName, ",")
arrPcName = Split(objSysInfo.ComputerN ame, ",")
Wscript.Echo "Name: " & Replace(arruName(0), "CN=", "") & vbCrLf &_
"Department: " & Replace(arrUname(1), "OU=", "") & vbCrLf &_
"Computername: " & Replace(arrPcName(0), "CN=", "")
----- SCRIPT END -----
It is supposed to be run from a login-script, so if another approch is preferable I am listening :-)
I hope someone can help.
----- EXISTING SCRIPT -----
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo
arruName = Split(objSysInfo.UserName,
arrPcName = Split(objSysInfo.ComputerN
Wscript.Echo "Name: " & Replace(arruName(0), "CN=", "") & vbCrLf &_
"Department: " & Replace(arrUname(1), "OU=", "") & vbCrLf &_
"Computername: " & Replace(arrPcName(0), "CN=", "")
----- SCRIPT END -----
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I made a little modification so every username is only listed once and updated everytime the user log in to a machine.
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo ")
arruName = Split(objSysInfo.UserName, ",")
arrPcName = Split(objSysInfo.ComputerN ame, ",")
Name = Replace(arruName(0), "CN=", "")
Department = Replace(arrUname(1), "OU=", "")
PCname = Replace(arrPcName(0), "CN=", "")
set cnMyDB= CreateObject("ADODB.Connec tion")
cnMyDB.Provider="Microsoft .Jet.OLEDB .4.0"
cnMyDB.Open "c:\UsersAndComputers.mdb"
sql = "SELECT username, Today FROM userdata WHERE username = '" & Name & "'"
set rs = cnMyDB.Execute(sql)
if rs.eof or rs.bof then
sqlstring = "insert into userdata (username, computername) values ('" & Name & "','" & PcName & "')"
else
sqlstring = "update userdata set username = '" & Name & "', computername = '" & PcName & "' where username = " & Name
end if
cnMyDB.execute sqlstring
cnMyDB.close
On Error Resume Next
Set objSysInfo = CreateObject("ADSystemInfo
arruName = Split(objSysInfo.UserName,
arrPcName = Split(objSysInfo.ComputerN
Name = Replace(arruName(0), "CN=", "")
Department = Replace(arrUname(1), "OU=", "")
PCname = Replace(arrPcName(0), "CN=", "")
set cnMyDB= CreateObject("ADODB.Connec
cnMyDB.Provider="Microsoft
cnMyDB.Open "c:\UsersAndComputers.mdb"
sql = "SELECT username, Today FROM userdata WHERE username = '" & Name & "'"
set rs = cnMyDB.Execute(sql)
if rs.eof or rs.bof then
sqlstring = "insert into userdata (username, computername) values ('" & Name & "','" & PcName & "')"
else
sqlstring = "update userdata set username = '" & Name & "', computername = '" & PcName & "' where username = " & Name
end if
cnMyDB.execute sqlstring
cnMyDB.close
ASKER
Just for the fun of it; how du I find the Users login name? objSysInfo.UserName finds the users name.