473,394 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

windows username to ms access

28
hi,

I'm trying to pull the windows username with jscript and save it to ms access field in a table, but it does not work. it does show the alert with the name of the user but does not save it to the ms access field. here i steh code that i'm using. please help

Expand|Select|Wrap|Line Numbers
  1. <SCRIPT type=text/javascript>
  2. <!--
  3. var WinNetwork = new ActiveXObject("WScript.Network");  
  4. alert(WinNetwork.userName);
  5.  
  6. var adOpenDynamic = 2;
  7. var adLockOptimistic = 3;
  8.  
  9. /* Path of database.
  10. */
  11. var strDbPath = "C:\Documents and Settings\ASPIRE\Desktop\ss1 upgrade\SS1\db1";
  12.  
  13. /*
  14. Here is the ConnectionString for Microsoft Access.
  15.  
  16. */
  17. var conn_str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + strDbPath;
  18.  
  19. function AddRecord() {
  20. var adoConn = new ActiveXObject("ADODB.Connection");
  21. var adoRS = new ActiveXObject("ADODB.Recordset");
  22.  
  23. adoConn.Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source='\\db1.mdb'");
  24. adoRS.Open("Select * From TimeTrackerTable Where Group = 'xxxx'", adoConn, 1, 3);
  25.  
  26. adoRS.AddNew;
  27. adoRS.Fields("Group").value = "(WinNetwork.userName)";
  28. adoRS.Update;
  29.  
  30. adoRS.Close();
  31. adoConn.Close();
  32. }
  33.  
  34.  
  35. function getAdoDb(strAdoType){
  36. if (window.ActiveXObject){
  37. return new ActiveXObject(strAdoType);
  38. }
  39. else{
  40. return ActiveXObject(strAdoType);
  41. }
  42. }
  43. </SCRIPT>
  44.  <INPUT id=Button1 onclick=EditRecord() type=button name=Command0 ;><BR>
  45. <SCRIPT language=javascript event=onclick for=Command0>
  46. try { if (MSODSC.DataPages.Count > 0)
  47. if (MSODSC.CurrentSection == null)
  48.     MSODSC.DataPages(0).Save();
  49. else
  50.     MSODSC.CurrentSection.DataPage.Save(); }    
  51. catch (e)
  52. { alert (e.description);}
  53. </SCRIPT>
  54.  
Regards,
xx
Sep 23 '08 #1
4 4160
pronerd
392 Expert 256MB
This is really more of an ActiveX question than a JavaScript one so you may want to try a forum that covers that.

I do see a number of issues, but I do not know if any of them are the problem.

First off the alert is being called because it is in the catch block. Some exception is being thrown causing the field value to not be set and causing the code in the catch block to execute instead.

Secondly the attributes in your HTML tags need to be surrounded by quotes. Third there is a semicolon in your input tag that should not be there.

The tags should look like this:
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT type="text/javascript">
Expand|Select|Wrap|Line Numbers
  1. <INPUT id="Button1" onclick="EditRecord()" type="button" name="Command0" />
Fouth the line below has a number of problems. All the attribute values need quotes. I do not see "event" or "for" as valid attributes for the script tag in any DOM documentation. Even if they are in IE how would you ever have an onclick event on a script tag. It is not rendered on the page and can not be clicked on.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT language=javascript event=onclick for=Command0>
Last but not lest what you are trying to do is ex termly unsafe. I would be very surprised if IE will let you run this code by default even in the local zone. So you will probably have to lower your IE security setting all the way for this code to run.
Sep 23 '08 #2
orajat
28
security would not be a concern, the only problem i see is in line 27.....
Sep 25 '08 #3
pronerd
392 Expert 256MB
security would not be a concern,
It may not be a concern, but it is a problem. It is very unlikely that IE will let you do direct local system access in the default security settings. You will have to lower your security settings to the lowest point to be able to do local system access like this.



the only problem i see is in line 27.....
And you are basing that on what? Line 17 is not even inside the try catch block where the exception is being thrown. For that matter I do not even see where the function for the code on line 27 is called. What is calling the getAdoDb() function?
Sep 25 '08 #4
orajat
28
by problem i meant that the whole excercise is to save the windows username in the ms access field, which is not hapenning....

xx

It may not be a concern, but it is a problem. It is very unlikely that IE will let you do direct local system access in the default security settings. You will have to lower your security settings to the lowest point to be able to do local system access like this.




And you are basing that on what? Line 17 is not even inside the try catch block where the exception is being thrown. For that matter I do not even see where the function for the code on line 27 is called. What is calling the getAdoDb() function?
Sep 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Newbie | last post by:
I am a newsbie to ASP but need to get a script together that will insert the Windows Username of the local machine into an access database. I get the errors from my code below, can anyone help me...
2
by: Joseph Geretz | last post by:
I'm having a credentialing problem in my web application. Actually, I don't think this is an IIS security issue, since I'm able to access the page I'm requesting. However, the executing page itself...
8
by: Jonathan Dixon | last post by:
I am developing an intranet and was wondering, when a user logs on is there a way to get the username of the windows account in asp.net. I have tried the following but they return the worker...
5
by: pberna | last post by:
Dear all, I built a Web Form application to start and stop a Windows Service remotely. I successful tested the application on Windows 2000 server + IIS. I must include the ASPNET user to the...
8
by: Raj Thakkar | last post by:
Hi, I am currenty working on a site for intranet. I have a user control in the header of every page that will be displayed only if people with certain username are surfing the site. These lists...
6
by: John Dalberg | last post by:
I want to automate the process of logging into an intranet. I want to pull out the username of the Windows user logged into the machine running the browser and use the username in my app. How can I...
4
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
1
by: James | last post by:
I have a VB windows forms application that accesses a Microsoft Access database that has been secured using user-level security. The application is being deployed using No-Touch deployment. The...
7
by: Alice Wong | last post by:
I am setting up my Web ASP.net application to connect to Sql server using windows authentication. I set up IIS to have integrated windows authenication and sql to allow Windows authentication....
4
by: =?Utf-8?B?QXZhRGV2?= | last post by:
ASP.Net 2. We are migrating to Windows 2008 64 bit Server with IIS 7 from Windows 2003 32 Bit with IIS 6. A few library classes we wrote uses impersonation in code like explained in this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.