I'm working with an old intranet site written in classic ASP. I'm trying to retrieve their username they logged into their machine with. Each user is logged into AD, but I can't retrieve it from the server since the intranet site does not use AD.
I was told I could use ActiveX in order to retrieve it. I did some research and I found the following code (javascript):
var wshshell = new ActiveXObject("WScript.shell");
var username = wshshell.ExpandEnvironmentalStrings("%username%");
Currently I'm using IE8 and I get an "Automation server can't create object" error on that first line.
1) Any ideas why I'm getting the error?
2) Is there a better way to be doing this given my limitations?
If this is done client-side, then you must have the user add the site to the Trusted Sites zone and set the security level to the lowest. Line 1 should work server-side, but I don't think line 2 is right.
Try this
var net = new ActiveXObject ( "WScript.NetWork" );
var username = net.UserName;
Basically, its impossible to retrieve client's Windows machine information using Javascript.
Because its scope is upto browser only.
For doing so you need to create COM object or say an Activex object, and using ASPX page you need to deploy it on Client's system at the very first time your page is accessed from a browser.
Now, ActiveX object has a featured to interact using javascript. You have to access the COM object or the class and function of the COM, which further interact with the system classes to get the system Information. i.e logged in client's windows user information.
var net = new ActiveXObject ( "WScript.NetWork" );
var username = net.UserName;
Above code is also initializing a COM object, if it is not deployed to your client system this script won't work.
Related
I am working on setting up a session variable only using JavaScript.
The requirement goes this way, A user logs into my application using SFTP client with UN/key, if I store the UN in a ctx variable its getting cleared after login process. I need the user name value to transfer any file to the back-end using my application. for this I am planning on using a session variable in JavaScript so that the UN will be saved as long as the session is established. I don't see any example with just JavaScript being used. is this possible ? I am not a JavaScript developer.
My application only supports XLS, XML and JavaScript.
I am thinking something like
this is just sudo code.
function username(UNvalue) {
var sessionun;
session.setvalue(sessionun) = UNvalue;
return sessionun;
}
Thanks,
Aswin.
I have created an online multiplayer card game using Adobe flash Professional. In this game multiple clients/account is not allowed, hence I need to detect whether the users are joining game from different devices or not. I can't simply do a server sided check for the IP-address because I still want e.g. people in the same office to be able to play together.
I have found some solution like reading the MAC address (Here) but the problem is that NetworkInfo.networkInfo.findInterfaces() works only on Adobe air, which is not my case.
Another solution could be using browser cookies, but the problem of this solution is that, the users can use e.g. Chrome and Firefox on the same computer.
As this a web game, using js could be also a solution, so I tag this question as js as well.
UPDATE
Using SharedObject does not work in this case, since google chrome uses its own storage.
Any suggestion will be appreciated.
Instead browser cookies you can use "flash cookies" - SharedObject. It is really simple and have mechanic similar to browser cookies, but stored in flash local storage.
UPDATE
Example:
var mySo:SharedObject = SharedObject.getLocal("host"); // get saved SO with name "host" if exists or create new if doesn't exist
mySo.data = {someProperty: "someData"}; // writing some data
var flushResult:Object = mySo.flush(); // saving data in local storage
...
var savedSO:SharedObject = SharedObject.getLocal("host");
trace(savedSO.data.someProperty); // output: someData
I have this line on my JavaScript
var objSysInfo=new ActiveXObject("ADSystemInfo");
var objUser=GetObject("LDAP://" + objSysInfo.UserName);
alert(objUser.displayName);
When I am logged in as an admin everything works fine, but if I am logged in as a non-admin account it starts to give exception on
var objSysInfo=new ActiveXObject("ADSystemInfo");
what seems to be the problem here and how will I solve it?
Are there any other alternatives to get the User Info from javascript, I just want to get the display name? (I know this wont work on FF and Chrome)
BTW this is the error I Get "automation server can't create object active x"
The error indicates that the browser security settings of the current user probably don't permit the instantiation of that particular ActiveX control. Unless you can change the browser security settings of the user, there's really nothing you can do about it programmatically (using JavaScript).
You don't get the same error as an admin user probably because of more lax security settings.
Try playing around with the ActiveX security settings in Internet Options and see if you can get it to work with the non-admin user. Maybe the solution for your end users is to provide documentation on how to change the ActiveX security settings.
I know that this question was asked a few years ago. However, i am answering just in case someone might need this information:
You might want to use something more like this:
**JavaScript**
var wshshell = new ActiveXObject("wscript.shell");
var userName = wshshell.ExpandEnvironmentStrings("%username%");
alert(userName);
**VBScript**
Set ObjSysInfo = CreateObject("ADSystemInfo")
strUser = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUser)
Dim userName = objUser.SAMAccountName
'In this case, username will be populated with whatever the AD requires for
'authentication when logging in
Maybe that'll work for you??
I've got a production site that has been working for years with a SQL Server 2000 default instance on server named MDWDATA. TCP port 1433 and Named Pipes are enabled there. My goal is to get this web app working with a copy of the database upgraded to SQL Server 2008. I've installed SQL2008 with SP1 on a server called DEVMOJITO and tested the new database using various VB6 desktop programs that exercise various stored procs in a client-server fashion and parts of the website itself work fine against the upgraded database residing on this named instance of SQL2008. So, while I am happy that the database upgrade seems fine there is a part of this website that fails with this Named Pipes Provider: Could not open a connection to SQL Server [1231]. I think this error is misleading. I disabled Named Pipes on the SQL2000 instance used by the production site, restarted SQL and all the ASP code still continued to work fine (plus we have a firewall between both database servers and these web virtual directories on a public facing webserver.
URL to my production virtual directory which demos the working page:
URL to my development v-directory which demos the failing page:
All the code is the same on both prod and dev sites except that on dev I'm trying to connect to the upgraded database.
I know there are dozens of things to check which I've been searching for but here are a few things I can offer to help you help me:
The code that is failing is server-side Javascript adapted from Brent Ashley's "Javascript Remote Scripting (JSRS)" code package years ago. It operates in an AJAX-like manner by posting requests back to different ASP pages and then handling a callback. I think the key thing to point out here is how I changed the connection to the database: (I cannot get Javascript to format right here!)
function setDBConnect(datasource)
{
var strConnect; //ADO connection string
//strConnect = "DRIVER=SQL Server;SERVER=MDWDATA;UID=uname;PASSWORD=x; DATABASE=StagingMDS;";
strConnect = "Provider=SQLNCLI10;Server=DEVMOJITO\MSSQLSERVER2008;Uid=uname;Pwd=x;DATABASE=StagingMDS;";
return strConnect;
}
function serializeSql( sql , datasource)
{
var conn = new ActiveXObject("ADODB.Connection");
var ConnectString = setDBConnect(datasource);
conn.Open( ConnectString );
var rs = conn.Execute( sql );
Please note how the connection string differs. I think that could be the problem but I don't know what to do. I am surprised the error returned says "named pipes" was involved because I really wanted to use TCP. The connection string syntax here is the same as used successfully on a different part of the site which uses VBScript which I'll paste here to show:
if DataBaseConnectionsAreNeeded(strScriptName) then
dim strWebDB
Set objConn = Server.CreateObject("ADODB.Connection")
if IsProductionWeb() Then
strWebDB = "DATABASE=MDS;SERVER=MDWDATA;DRIVER=SQL Server;UID=uname;PASSWORD=x;"
end if
if IsDevelopmentWeb() Then
strWebDB = "Provider=SQLNCLI10;Server=DEVMOJITO\MSSQLSERVER2008;Database=StagingMDS;UID=uname;PASSWORD=x;"
end if
objConn.ConnectionString = strWebDB
objConn.ConnectionTimeout = 30
objConn.Open
set oCmd = Server.CreateObject("ADODB.Command")
oCmd.ActiveConnection = objConn
This code works in both prod and dev virtual directories and other code in other parts of the web which use ASP.NET work against both databases correctly. Named pipes and TCP are both enabled on each server. I don't understand the string used by the Pipes but I am using the defaults always.
I wonder why the Javascript call above results in use of named pipes instead of TCP. Any ideas would be greatly appreciated.
Summary of what I did to get this working:
Add an extra slash to the connection string since this is server-side Javascript:
Server=tcp:DEVMOJITO\MSSQLSERVER2008,1219;
Explicitly code tcp: as a protocol prefix and port 1219. I learned that by default a named instance of SQL uses dynamic porting. I ended up turning that off and chose, somewhat arbitrarily, the port 1219, which dynamic had chosen before I turned it off. There are probably other ways to get this part working.
Finally, I discovered that SET NOCOUNT ON needed to be added to the stored procedure being called. Otherwise, the symptom is the message: "Operation is not allowed when the object is closed".
I was wondering if it was possible to grab the username of the account logged into the computer. I wanted to print the username of the person that is printing out the pdf file.
I was thinking about trying to grab the %username% environment variable. Does not seem to be possible.
In Acrobat JavaScript, many local system parameters are considered privileged. The user's login name is one of these. In order to access the "identity" object the JavaScript code has to be executed from a trusted context. Code inside a PDF doesn't qualify. Or at least it doesn't normally. If the local system user has given explicit permission to the PDF, then it can access privileged data. But obviously this isn't a general purpose solution. Typically the "identity" object is only accessible to Folder Level Automation scripts.
Thom Parker
www.pdfscripting.com
take a look a the identity object.
name = identity.name; //gives you the user name that the user entered in the Identity preferences panel
userName = identity.loginName; //login name as registered by the operating system
This may be possible to some extent server-side. Here's an NTLM auth module for Apache/Unix, and here's one for Apache/Windows.