Gettin error bjSysInfo = CreateObject("ADSystemInfo") in classical ASP in IIS7.0 - iis-7

I'm getting undefined object CreateObject("ADSystemInfo") when I embed the code in classical asp that is hosted in IIS7.0 on Windows Server 2008. When I excute the same code on that server using VBscript it is working fine. Could some one help me. I need to know if I need to make any server settings changes
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
arrGroups = objUser.memberOf

This is because what you wrote about is actually VBScript, and not Classic ASP.
You can run this from the cmd window and it should work fine. But to convert it to ASP, you have to do a couple things.
Surround your code with
<%
... code here
%>
And then change every instance of CreateObject to Server.CreateObject
Your code would look like this:
<%
Set objSysInfo = Server.CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
arrGroups = objUser.memberOf
%>
Finally, make sure that the IIS webserver is running as a user that has the correct permissions.

Related

System.Management.dll not recognised .Net 4.6

I am having a really wired issue where I have created a new ASP.Net 4.6 web application (Visual Studio 2015 Community Edition) and everything works fine.
The app will compile without any issues at all but as soon as I try to run the app on the development machine (Windows 10 Enterprise) I get the following error every time and I cannot figure out why?
BC30002: Type 'ConnectionOptions' is not defined.
The code I am using is as follows:
Dim Options As New ConnectionOptions()
Options.Username = HttpContext.Current.Application("WMIUser")
Options.Password = HttpContext.Current.Application("WMIPsssword")
Dim scope As New ManagementScope("\\" & server_name & "\root\cimv2", Options)
scope.Connect()
Dim objectQuery As New ObjectQuery("SELECT FreeSpace FROM Win32_LogicalDisk where DeviceID=""" + deviceId + ":""")
Dim objectSearcher As New ManagementObjectSearcher(scope, objectQuery)
Dim objectCollection As ManagementObjectCollection = objectSearcher.[Get]()
For Each m As ManagementObject In objectCollection
Dim FreeSpace As Double = Convert.ToDouble(m("FreeSpace"))
Next
I have a reference to the System.Management DLL in the references for the application and I have an Imports declaration for it also.
Has anyone come across this before? My searching all leads back to the DLL not being referenced in the application but I have added and removed and re-added without any change.
Please help this is driving me nuts :-(
OK so this is a funny one, posting up just in case someone else comes across the issue.
The way I resolved this problem on the development machine was under References for the project, you have the option to copy local, set this to true and rebuilt the application, ran it and hey presto it all worked.
I can only assume that this could be a permissions thing but this works for the moment anyway.
Hope this helps someone in the future.

Unable to perform Response.write

I have a classic asp page for which I would like to perform the parametrized style asp debugging. The debugging is for finding the SQL used. I am trying to debug in Visual Web developer 2010 but the debug options are grayed out. When I put in Response.Write I am getting the asp page as usual. Kindly assist.
The code snippet is below:
'//Create Recordset
Set SKUOutput=Server.CreateObject("ADODB.Recordset")
'//Open Recordset
SKUOutput.Open SKUQuery, SKUConnection, adOpenDynamic, adLockOptimistic
recordCount=SKUOutput.RecordCount
SKUOutput.Close
Set SKUOutput=Nothing
'//Create Recordset
Set SKUOutput=Server.CreateObject("ADODB.Recordset")
SKUOutput.Open SKUQuery, SKUConnection, adOpenDynamic, adLockOptimistic
response.Write SKUQuery
response.End
I'd put your response.write statement before skuoutput.open
I think the greyed out options are for .net only - the way to debug classic asp is to run it on your server (or development server) and read the error message in the output.

Run vbscript on serverside using asp.net

sorry in advance for any orthographic mistakes (english is not my first language).
I want to run a .vbs file on the server side using a button in an asp.net application (that is, from the client side). The vbs file could contain something as simple as a msgBox("Hello World!") and it's located in the server where the page is hosted, moreover, it's in the same folder as the .aspx file.
I've tried to use this code in the Button_Click event:
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WorkingDirectory = Request.MapPath("~/");
process.StartInfo.FileName = Request.MapPath("displayHelloWorldOnTheServer.vbs");
process.Start();
but the script doesn't seem to be running.
Any suggestions?
A vbs script doesn't compile and execute. It's interpreted by wscript or cscript.
Try
process.StartInfo.FileName = "cscript";
process.StartInfo.Arguments = Request.MapPath("displayHelloWorldOnTheServer.vbs");
process.Start();

How to reference PowerShell Module within ASP.NET Site

I'm trying to figure out how to use the Microsoft Online Services Migration Toolkit PowerShell Commands from within an ASP.NET website (using vb.NET).
I've started off using a guide on how to use PowerShell in ASP.NET - from here: http://devinfra-us.blogspot.com/2011/02/using-powershell-20-from-aspnet-part-1.html
I'm trying to work out how to implement the Online Services Migration Toolkit PowerShell cmdlets.
Here is a snippet from my code-behind:
Sub GetUsers()
Dim iss As InitialSessionState = InitialSessionState.CreateDefault()
iss.ImportPSModule(New String() {"MSOnline"})
Using myRunSpace As Runspace = RunspaceFactory.CreateRunspace(iss)
myRunSpace.Open()
' Execute the Get-CsTrustedApplication cmdlet.
Using powershell As System.Management.Automation.PowerShell = System.Management.Automation.PowerShell.Create()
powershell.Runspace = myRunSpace
Dim connect As New Command("Get-MSOnlineUser -Enabled")
Dim secureString As New System.Security.SecureString()
Dim myPassword As String = "ThePassword"
For Each c As Char In myPassword
secureString.AppendChar(c)
Next
connect.Parameters.Add("Credential", New PSCredential("admin#thedomain.apac.microsoftonline.com", secureString))
powershell.Commands.AddCommand(connect)
Dim results As Collection(Of PSObject) = Nothing
Dim errors As Collection(Of ErrorRecord) = Nothing
results = powershell.Invoke()
errors = powershell.Streams.[Error].ReadAll()
For Each obj As PSObject In results
Response.Write(obj.Properties("Identity").Value.ToString())
Next
End Using
End Using
End Sub
When I try to run the code via the page, I'm getting the following error
The term 'Get-MSOnlineUser -Enabled' is not recognized as the name of
a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path
is correct and try again.
So I'm guessing I haven't worked out how to import the Online Services Migration Toolkit PowerShell CmdLets. I'm also not exactly sure if the line:
iss.ImportPSModule(New String() {"MSOnline"})
Is exactly correct. Is there a way I can verify the Module name?
I'm also unsure of where and how to reference the .dll files. At the moment I have copied them to my bin folder but I can't add them as references, so how does the ImportPSModule statement know where to find them? Especially when the website is published to the final production server.
One other question, should I be using the x86 or x64 cmdlets? I'm developing on Win7 x64, but not sure if the website builds as x86 or x64? Do I need to find out what architecture the server is?
"Get-MSOnlineUser -Enabled" is not a command; "Get-MSOnlineUser" is. I'm a bit confused how you got it correct further down the script with connect.Parameters.Add("Credential", ...) but didn't do the same thing for -Enabled.
Use connect.AddArgument("Enabled") or connect.Parameters.Add("Enabled", true) and you should be good to go.

Alternative to Server.CreateObject

I am writing a navigation system in classic ASP (on Windows CE).
I require a way to dynamically include navigation files based on the calling script.
I have come up with the following code that includes nav.inc that is located in the folder of the calling script to allow different folders to have different navigational features.
This works fine on my Windows test machine but NOT when I deploy to Windows CE. The code and error is shown below. If anyone can provide a work around or any feedback that would be great. Thanks
Code:
<%
'Get path name
Dim i
fullname = Request.ServerVariables("SCRIPT_NAME")
my_array=split(fullname,"/")
fname=my_array(ubound(my_array))
fname = ""
For i = 0 to ubound(my_array) - 1
fname = fname & my_array(i) & "/"
Next
fname = fname & "nav.inc"
Set fs=Server.CreateObject("Scripting.FileSystemObject")
If (fs.FileExists(Server.MapPath(fname)))=true Then
Server.Execute(fname)
End If
%>
Error:
Microsoft VBScript runtime error:
'800a01b6'
Description: Object doesn't support
this property or method:
'Server.CreateObject'
If I alter the code to just say Set fs=CreateObject("Scripting.FileSystemObject") I get the following error:
Microsoft VBScript runtime error:
'800a01ad'
Description: ActiveX component can't
create object:
'Scripting.FileSystemObject'
Update I have just tried running Server.Execute directly and this fails too. It looks like I do not have any access to the Server object. Is there any work around for this as well?
CreateObject and Execute are not supported in Windows CE.
The <OBJECT> tag is not supported also, so, you are out of luck, sorry.
Server Object Implementation
---------------------------
The Server object provides access to methods and properties on the server.
Most of these methods and properties serve as utility functions.
Server method Windows CE implementation
-----------------------------------------
CreateObject Not supported
Execute Not supported
GetLastError Not supported
HTMLEncode Not supported
MapPath Fully supported
ScriptTimeout Not supported
Transfer Not supported
URLEncode Fully supported
Source

Resources