Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBscript variable in text box

Status
Not open for further replies.

ckugo

IS-IT--Management
Jan 6, 2004
165
0
0
US
I am trying to pull some information from a vbscript varible into a text box on a web page to later then be submitted to a database via an asp script. The asp script and database are funtioning fine, but I cannot seem to pull the vbscript variable into the text box on the form. Below is my entire htm code:

<html>
<head>
<title>List Change</title>

</head>
<body bgcolor="white" text="black">


<script type="text/vbscript">
Const HKEY_CURRENT_USER = &H80000001
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set wshshell = CreateObject("Wscript.shell")
oReg.EnumKey HKEY_CURRENT_USER, "Software\Microsoft\Protected Storage System Provider", arrSubKeys
sid = arrsubkeys(0)
CommonName = wshshell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\" & sid & "\Distinguished-Name")
MyArray = Split(commonname,",",-1,1)
CommonNameValue = Replace(MyArray(0),"CN=","")

'VB Script variable
document.write(commonnamevalue)


</script>

<!-- Begin form code -->
<form name="form" method="post" action="List.asp">


'Need to pull variable in for value here
Name: <input type="text" name="FirstName" value = "<%=commonnamevalue%>">

<input type="submit" name="Submit" value="Submit">
</form>
<!-- End form code -->
</body>
</html>


I am basically trying to pull a user's name as it is stored in Active diretory and in order to do that I am pulling the current user's sid and then comparing it to all of the sid's in the registry and then splitting out the distinguised name key.

Any help is really appreciated and if something doesn't make sense please let me know. Also, if anyone has any better suggestions on how to submit a vbscript variable to a database via asp please let me know. This is my first time doing this, so there may be a more efficient way of doing it.

Thanks,

Chris
 
I'm not sure what you have there. What type of script is it? Is it

a) ASP
b) WSF
c) HTML on the client

It has bits of ASP in it but the rest of the VBScript is not in asp <% .. %>; that's why I'm asking.
 
[1] You cannot use getobject() to get to the running activex object on the client. This is a strictly blocked operation for security reason. So the only option from the face of the script shown is to serve it as hta from trusted source.

[2] There are really bad naming scheme in the page. (Bad, I don't mean just my personal preference, it has real material repercussion. Alternative names below are suggestive only.)

[3] Comment in html body is <!-- --> not apostroph.

[4] To put the value to a textbox control, you need to [4.1] wait for the page to be rendered and [4.2] reference to it (as shown infra).
[tt]
[blue]<!-- a hta, not html/asp -->[/blue]
<html>
<head>
<title>List Change</title>
<script type="text/vbscript">
[blue]sub window_onload[/blue]
Const HKEY_CURRENT_USER = &H80000001
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv")
Set wshshell = CreateObject("Wscript.shell")
oReg.EnumKey HKEY_CURRENT_USER, "Software\Microsoft\Protected Storage System Provider", arrSubKeys
sid = arrsubkeys(0)
[blue]'Are you sure you do thing here on HKLM, not HKCU?[/blue]
CommonName = wshshell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\" & sid & "\Distinguished-Name")
MyArray = Split(commonname,",",-1,1)
CommonNameValue = Replace(MyArray(0),"CN=","")

'VB Script variable
'document.write(commonnamevalue)
[blue]document.formname.FirstName.value=CommonNameValue[/blue]
[blue]end sub[/blue]
</script>
</head>
<body bgcolor="white" text="black">
<!-- Begin form code -->
[red]<!-- bad naming[/red]
<form name="form" method="post" action="List.asp">
[red]-->[/red]
<form name="form[blue]name[/blue]" method="post" action="List.asp">
[red]<!--[/red] 'Need to pull variable in for value here [red]-->[/red]
[red]<!-- wrong variable rendering, besides it is never meant to be server-side[/red]
Name: <input type="text" name="FirstName" value = "<%=commonnamevalue%>">
[red]-->[/red]
[blue]Name: <input type="text" name="FirstName" />[/blue]
[red]<!-- bad naming[/red]
<input type="submit" name="Submit" value="Submit">
[red]-->[/red]
<input type="submit" name="Submit[blue]button[/blue]" value="Submit">
</form>
<!-- End form code -->
</body>
</html>
[/tt]
 
Thanks for the replies. Ya, after going through that, it is really bad naming. Thanks for the advice! In the code below I am pulling the HKCU sid and storing it in the variable sid, I am then reading the HKLM hive and using the sid value from the HKCU to get the CN value.

oReg.EnumKey HKEY_CURRENT_USER, "Software\Microsoft\Protected Storage System Provider", arrSubKeys
sid = arrsubkeys(0)
'Are you sure you do thing here on HKLM, not HKCU?
CommonName = wshshell.RegRead("HKLM\Software\Microsoft\Windows\CurrentVersion\Group Policy\State\" & sid & "\Distinguished-Name")


Thanks so much for your help,

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top