Solved

Need help with VBS and HTML

Posted on 2009-04-09
12
303 Views
Last Modified: 2013-12-24
Hello I have a script that when ran as a .vbs file it shows me all locked user accounts. When i try to put it into an html file it wont work.

Am i missing something? You would think if it runs as a .vbs file it would run in an html file.
<html>
 

<head>

    <title>Woot</title>

	    <script type="text/vbscript">
 

	   On Error Resume Next 
 

	   Const ADS_SCOPE_SUBTREE = 2 
 

	   Set objConnection = CreateObject("ADODB.Connection") 

	   Set objCommand =   CreateObject("ADODB.Command") 

	   objConnection.Provider = "ADsDSOObject" 

	   objConnection.Open "Active Directory Provider" 

	   Set objCommand.ActiveConnection = objConnection 
 

	   objCommand.Properties("Page Size") = 1000 

	   objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

	   objCommand.CommandText = _ 

	      "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=domain,dc=domain,dc=com' WHERE objectCategory='user'" 
 

	   Set objRecordSet = objCommand.Execute 

	   objRecordSet.MoveFirst 
 

	   Do Until objRecordSet.EOF 

	   strDN = objRecordset.Fields("distinguishedName").Value 

	   Set objUser = GetObject ("LDAP://" & strDN) 
 

  	     If objuser.isAccountlocked = True Then 

            document.write objuser.samAccountName

			objRecordSet.MoveNext

 	     Else 

	        objrecordset.MoveNext 

		 End If

	   Set objuser = Nothing 

	   Loop 

</script>

</head>

<body>

</body>

</html>

Open in new window

0
Comment
Question by:teepes
  • 6
  • 6
12 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 24107286
Place your <script> 'between' your </head> & <body>
0
 

Author Comment

by:teepes
ID: 24107306
I have tried putting it in everyspot and nothing works.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24107349
Are you trying to develop an HTA?
If so, name the file 'filename.hta'

Otherwise, ignore this post.
<html>

 

<head>

   <title>Woot</title>
 

   <HTA:Application ID="myApp"

        ApplicationName="My App"

   >

</head>

 

<script Language="VBScript">

 

           On Error Resume Next 

 

           Const ADS_SCOPE_SUBTREE = 2 

 

           Set objConnection = CreateObject("ADODB.Connection") 

           Set objCommand =   CreateObject("ADODB.Command") 

           objConnection.Provider = "ADsDSOObject" 

           objConnection.Open "Active Directory Provider" 

           Set objCommand.ActiveConnection = objConnection 

 

           objCommand.Properties("Page Size") = 1000 

           objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

           objCommand.CommandText = _ 

              "SELECT distinguishedName FROM 'LDAP://dc=domain,dc=domain,dc=domain,dc=com' WHERE objectCategory='user'" 

 

           Set objRecordSet = objCommand.Execute 

           objRecordSet.MoveFirst 

 

           Do Until objRecordSet.EOF 

           strDN = objRecordset.Fields("distinguishedName").Value 

           Set objUser = GetObject ("LDAP://" & strDN) 

 

             If objuser.isAccountlocked = True Then 

            document.write objuser.samAccountName

                        objRecordSet.MoveNext

             Else 

                objrecordset.MoveNext 

                 End If

           Set objuser = Nothing 

           Loop 

</script>
 

<body>

</body>

</html>

Open in new window

0
 

Author Comment

by:teepes
ID: 24107397
well basically what i'm doing is building a vista gadget. I'm not sure if it will work with .hta.
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24107642
Oh...haven't tried that myself yet...don't even know where to begin.
However, I would suggest simplifying the code greatly - perhaps just include an msgbox or something to alert you that the script section is even running...
0
 

Author Comment

by:teepes
ID: 24108022
The .hta isnt working with my gadget i need it to be HTML.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:teepes
ID: 24108537
I did some toying around with the script some more, and noticed that if i do the following code in the else statement it will put put hello world for every account not locked out. Then i tried to put in document.write (objuser.samAccountName) in the else statement and it's blank. Don't know if that will tell you guys anything.
  	     If objuser.isAccountlocked = True Then 

                 document.write objuser.samAccountName

	        objRecordSet.MoveNext

 	     Else 

	        document.write ("hello world")

                 objrecordset.MoveNext 

		 End If

	   Set objuser = Nothing 

	   Loop 

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24108686
testing some things now...stand by...
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24108770
    Set objUser = GetObject ("LDAP://" & strDN)

may be your issue...

"Thats because, at heart, a gadget is nothing more than a Web page, and, for security reasons, Web pages arent able to make use of GetObject. "

ref: http://www.microsoft.com/technet/scriptcenter/topics/vista/gadgets-pt1.mspx

Doesn't look like that can be accomplished...
0
 

Author Comment

by:teepes
ID: 24109001
Thanks sirbounty

I am going to award you the points. I posted another question on how i could do something like what i need if any ideas come to mind.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24310138.html 
0
 

Author Closing Comment

by:teepes
ID: 31568518
Thanks, if you can think of a way to accomplish what im trying answer my new post

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24310138.html 
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 24109028
Thanx - already working on a 'workaround' of sorts...I'll post in the other thread...
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
What about 192.168.1.0/28 3 30
If-Then-Else ASP problem 6 46
Form Processing in PHP 11 30
Problem to With line 4 37
Read about why website design really matters in today's demanding market.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now