Link to home
Start Free TrialLog in
Avatar of Kasper Katzmann
Kasper KatzmannFlag for Denmark

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.ComputerName, ",")

Wscript.Echo      "Name: " & Replace(arruName(0), "CN=", "") & vbCrLf &_
          "Department: " & Replace(arrUname(1), "OU=", "") & vbCrLf &_
          "Computername: " & Replace(arrPcName(0), "CN=", "")
----- SCRIPT END -----
ASKER CERTIFIED SOLUTION
Avatar of PatG042800
PatG042800
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kasper Katzmann

ASKER

Yep, thats it. Great and effective.

Just for the fun of it; how du I find the Users login name? objSysInfo.UserName finds the users name.
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.ComputerName, ",")

Name = Replace(arruName(0), "CN=", "")
Department = Replace(arrUname(1), "OU=", "")
PCname = Replace(arrPcName(0), "CN=", "")

set cnMyDB= CreateObject("ADODB.Connection")
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