Application Pool Status in IIS 7 - iis

I want to get status of a Application Pool. I have vbscript taken from here.
strArgAppPool = Wscript.Arguments.Unnamed.Item(0)
Const noError = False
' Establish the connection to the WMI provider
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")
' Search the AppPool passed as argument in the list of application pools
Set oAppPool = oWebAdmin.Get("ApplicationPool.Name='" & strArgAppPool & "'")
' Create nice messages for pool states
Select Case oAppPool.GetState
Case 0
StateDescription = "STARTING"
outputStatus = "WARNING! "
outputCode = 1
Case 1
StateDescription = "STARTED"
outputStatus = "OK! "
outputCode = 0
Case 2
StateDescription = "STOPPING"
outputStatus = "WARNING! "
outputCode = 1
Case 3
StateDescription = "STOPPED"
outputStatus = "CRITICAL!! "
outputCode = 2
Case 4
StateDescription = "UNKNOWN"
outputStatus = "UNKNOWN? "
outputCode = 3
Case Else
StateDescription = "UNDEFINED VALUE"
outputStatus = "UNKNOWN? "
outputCode = 3
End Select
' Output
Wscript.Echo outputStatus & oAppPool.Name & ": " & StateDescription
' Error handling
If noError = true Then
' Error message
Wscript.echo "UNKNOWN: Error during the WMI query for app pool " & strArgAppPool & " !"
' Exit & return code
WScript.Quit(3)
Else
' Clean exit
WScript.Quit(outputCode)
End If
Through a batch file I am trying to run it as
status1.vbs "DefaultAppPool"
But I ended up with this
Is it some service is not started? I have tried running the vb script directly. I have tried passing arguments without quotes and all similar stuff. I don't write scripts, but got to do it this time.
Error dialog indicates line 5, Set oWebAdmin = GetObject("winmgmts:root\WebAdministration"). I have tried everything I could in last 5 hours. I have a readymade script and I am not able to run it. Shame and was not willing post this question all this while. But lost in end. Thanks for any help.
Also I have a working script for IIS 6. I am calling this script through PsExec on a remote server. But that's not working in IIS 7. Let me know if anyone want me to post it. Also I am using IIS 7 and Server 2008 R2 now and will be running this script using PsExec on remote server.

You don't have the role service IIS Management Scripts and Tools installed. Launch Server Manager, go to Roles → Web Server (IIS), and install the missing service.

Related

Authenticating to AD from a workgroup IIS installation

I am using classic ASP (I know I should move on to ASP.NET) and a workgroup IIS installation. Can I get it to authenticate to AD? So, far it just won't connect to AD.
It is working on my desktop that is domain joined without any hassles but the same code won't work from the workgroup machine.
Session( "signon_domain" ) = UCase( strSignOnDomain )
Session( "signon_userid" ) = LCase( strSignOnUserID )
' Set the AD path to connect to
strADsPath = "WinNT://" & strSignOnDomain
' Bind to the AD path
Set objADsPath = GetObject( strADsPath )
' Get the namespace
strADsNamespace = "WinNT:"
' Bind to the namespace
Set objADsNamespace = GetObject( strADsNamespace )
' Turn on error handling
On Error Resume Next
' Connect to AD with the provided credentials
Set objADsAuthenticate = objADsNamespace.OpenDSObject( strADsPath, strSignOnDomain & "\" & strSignOnUserID, strSignOnPassword, 0 )
' Check for any errors
If Err.Number <> 0 Then
' Specify the error to display
strMessage = "User ID or password or domain incorrect."
Session( "signon" ) = ""
Else
Session( "signon" ) = "successful"
End If
' Turn off error handling
On Error Goto 0
' Clear variables
Set objADsAuthenticate = Nothing
Set objADsNamespace = Nothing
Set objADsPath = Nothing
strADsNamespace = Empty
strADsPath = Empty
Expecting a response from AD but instead it isn't connecting to AD at all.

Excel VBA: Stopping and Starting a background Service

Is it possible to stop and start a background service.
There is a third party service that is interfering with an Excel Plug-In. I want to temporarily stop it when I run my code, and then turn it back on at the end.
Whenever you want to do something like this a Google using "WMI" will probably get you something useful.
For example -
From: https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/stopservice-method-in-class-win32-service
Set ServiceSet = GetObject("winmgmts:").ExecQuery( _
"select * from Win32_Service where Name='ClipSrv'")
for each Service in ServiceSet
RetVal = Service.StopService()
if RetVal = 0 then
WScript.Echo "Service stopped"
elseif RetVal = 5 then
WScript.Echo "Service already stopped"
end if
next
Similarly: https://learn.microsoft.com/en-us/windows/desktop/cimwin32prov/startservice-method-in-class-win32-service
Set ServiceSet = GetObject("winmgmts:").ExecQuery( _
"select * from Win32_Service where Name='ClipSrv'")
for each Service in ServiceSet
RetVal = Service.StartService()
if RetVal = 0 then WScript.Echo "Service started"
if RetVal = 10 then WScript.Echo "Service already running"
next

Error handing page not trapping all errors

I have this simple error checking page on my classic ASP website and have a custom error page set up so that scripting errors (500 and 500.100) call this error page so that errors are logged into a MySQL table:
<!--#INCLUDE file="db_connection.asp" -->
<%
On Error Resume Next
'crappy function I use
Function newstr(str)
newstr = Server.HTMLencode(str)
newstr = Replace(newstr, "'","''")
newstr = Replace(newstr, "\","\\")
newstr = Replace(newstr, chr(10), "<br />")
End Function
'get all form data and put it into a variable
For ix = 1 to Request.Form.Count
fieldName = Request.Form.Key(ix)
fieldValue = Request.Form.Item(ix)
bb = bb & fieldName & ": " & fieldValue & vbcrlf
Next
bb = newstr(bb)
set objError = Server.getLastError()
strNumber = objError.AspCode & " : " & Err.Number
strSource = objError.Category
strPage = objError.File
strDesc = objError.Description & " : " & ObjError.ASPDescription & " :: " & Err.Description
strDesc = newstr(strDesc)
strCode = Server.HTMLEncode(objError.Source)
If strCode = "" then strCode = "No code available"
strLine = ObjError.Line
strASPDesc = ObjError.ASPDescription
strRemoteAddr = Request.ServerVariables("REMOTE_ADDR")
strLocalAddr = Request.ServerVariables("LOCAL_ADDR")
ref = request.servervariables("HTTP_REFERER")
str = request.servervariables("QUERY_STRING")
ip_url = strRemoteAddr
ua = newstr(request.servervariables("HTTP_USER_AGENT"))
totalstring = strPage & "?" & str
sql = ""
sql = SQL & " INSERT INTO error_log ("
sql = SQL & " er_time, "
sql = SQL & " er_number, "
sql = SQL & " er_source, "
sql = SQL & " er_page, "
sql = SQL & " er_desc, "
sql = SQL & " er_code, "
sql = SQL & " er_line, "
sql = SQL & " er_remote_addr, "
sql = SQL & " er_local_addr, "
sql = SQL & " er_str, "
sql = SQL & " er_ref, "
sql = SQL & " er_type, "
sql = SQL & " ip_url, "
sql = SQL & " er_br, "
sql = SQL & " er_form"
sql = SQL & " ) VALUES ("
sql = SQL & " now(),"
sql = SQL & " '" &strNumber&"',"
sql = SQL & " '"&strSource&"',"
sql = SQL & " '"&strPage&"',"
sql = SQL & " '"&strDesc&"',"
sql = SQL & " '"&strCode&"',"
sql = SQL & " '"&strLine&"',"
sql = SQL & " '"&strRemoteAddr&"',"
sql = SQL & " '"&strLocalAddr&"',"
sql = SQL & " '"&totalstring&"',"
sql = SQL & " '"&ref&"',"
sql = SQL & " '500',"
sql = SQL & " '"&ip_url&"',"
sql = SQL & " '"&ua&"',"
sql = SQL & " '"&bb&"') "
oConn.Execute(sql)
%>
The trouble I'm finding is that lots of lines keep ending up in the error log, but are not triggering Server.getLastError, because all of the variables from that are NULL. And I know that someone isn't directly visiting the URL of the error page because the "strPage" variable, (set by objError.File) is populated.
However, if I visit the page that is erroring, it always works fine.
The pages which are in the error log always have a querystring associated with them - but the ID of that always varies - so e.g. it might be that the "totalstring" (made up of objError.File concatenated with a question mark followed by request.servervariables("QUERY_STRING") could be:
/music/view.asp?id=192
/designs/page.asp?id=5775
/designs/page.asp?id=5797
They all error in the same place, which is:
e = newstr(request("id"))
Where "newstr" is the function mentioned at the top of this page. I know that that function is a load of crap and risks SQL injections etc.
However, in this case, I can't work out why the pages are erroring as they always work fine for me and most of the site users.
What's strange is that the IP addresses of the users getting the errors are always from the same ISP - generally one ISP in Germany.
Could something suspicious be going on in the background? Is there any additional logging I could do to get to the bottom of this?
Update 30th July 2015
Thanks to answer provided by #John, I was able to get to the bottom of this, and avoided errors by putting this at the top of every page:
<%
''get the cookie data
ck = Request.ServerVariables("HTTP_COOKIE")
'' does the cookie data contain "; = true;" somewhere, does not matter where
v1 = instr(ck, "; =true;")
''if the cookie data starts with "=true;" OR if "; =true;" appears somewhere in the cookie, then redirect somewhere else
if left(ck,6) = "=true;" OR v1 > 0 then response.redirect ("somewhere-else.asp")
%>
More info also here:
https://forums.iis.net/p/1226865/2106015.aspx?Re+Request+Cookies+generate+80004005+2147467259+error+if+cookie+with+no+name
Seems to be some hacking type activity originating from ISP Hetzner Online AG
I have been getting a lot of similar errors where no error number is recorded. I found the problem due to the cookies that were being sent and at least one of the cookies having no name.
When you do Request("id") it checks the querystring, form post and then cookies. Classic ASP does not seem capable of handling cookies where there is no name and fails in this situation with an error.
Looking at the requests I am receiving they do look like unusual hack attempts targeting cookies.
To see if this is the case I would suggest you log the cookie HTTP header as well.
One option would be to change from Request to Request.QueryString or Request.Form depending on how you are expecting the parameter to be passed (GET or POST).
If that is not an option then you could add some code to check for this no name cookie problem, something like this should do the job:
On Error Resume Next
Request.Cookies("test")
If Err.Number <> 0 Then Server.Transfer("/common/500.asp")
On Error Goto 0
This just checks whether it is possible to read a cookie, and it doesn't matter what cookie name you use or whether the cookie exists or not. It will end execution if invalid cookies are sent. If you have an include file that is run on every request you could add this to the beginning.
See my own SO question for some further information.

Autoit controls

I use ControlSend() to send hotkeys in a different window. Problem is to find the right window control. Or the control is right and there is an unknown issue. These are the controls:
Title: PokeMMO
Class: LWJGL
controlID: still unknown
Process: javaw.exe
$handle = WinGetHandle("[TITLE:PokeMMO; CLASS:LWJGL]")
ControlSend($handle, Default, $handle, "{Down}")
Didn't work.
Global $sProcess = "javaw.exe" ; Process PokeMMO
ControlSend(_Process2Win($sProcess), "", "", "{DOWN}")
Func _Process2Win($pid)
If IsString($pid) Then $pid = ProcessExists($pid)
If $pid = 0 Then Return -1
$list = WinList()
For $i = 1 To $list[0][0]
If $list[$i][0] <> "" And BitAND(WinGetState($list[$i][1]), 2) Then
$wpid = WinGetProcess($list[$i][0])
If $wpid = $pid Then Return $list[$i][0]
EndIf
Next
Return -1
EndFunc ;==>_Process2Win
Didn't work. I also tried this:
Run("C:\path\path\path\PokeMMO.exe")
WinWait("[CLASS:LWJGL]")
Local $sControl = ControlGetFocus("[CLASS:LWJGL]")
MsgBox(0, "ControlGetFocus Example", "The control that has focus is: " & $sControl)
Stystem Message: Java Virtual Machine Launcher - A Java Exception has occured ERROR!
A guide on YouTube tells to install a different version of Java.
Try using Title and text parameter, but leave the controlID parameter free like "" or ''. That should also work. Good luck.

Classic ASP site page not responding, but does work if page is requested within the server

We have a classic ASP site that is been hosted in IIS 7.5. I am looking at this weird behavior and I am trying to find a resolution for this. Now the problem with one of the many pages (not all pages) is http://website.com/admin/customers.asp
If this page is requested from a browser within the server where the application is hosted, then everything works fine.
If the page is requested ouside the server, i.e from some machine then the page never responds. and the wierd part here is that the IIS is not returing any status codes either, when looked via firebug...I see a staus of "(aborted)".
Now here is a more interesting point, the page requested displays 7 customer records, however if I tweak the sql query to return 5 or less customers then everything works fine.
I have been working on this issue from past 1 day and so far figured that code is not a problem here, as it works in the server with the same data and database. Also, the page work fine if 5 or less records are returned...
I would really appreciate if anyone could help me out with this problem...
So, as I've mentioned the problem was with the server that I was testing with and it turned out that we had to set the TCP/IP off load setting to disable(Via Broadcom client UI).
Although, still need to figure out why we have to do this...
Thanks a lot for your time and suggestions...
At first sight, I do believe you have a problem between the internet and the machine where the website is hosted (proxy problems, firewalls, etc). However, since you stated that the problem is solved when you change a part of your code to show 5 results instead of 7, I think that you are iterating through a recordset without specifying the code for it to roll over:
rs.moveNext
As I've suggested in a comment, try debugging the issue by writing to text file and hopefully finding where the code get stuck. Sample code will be:
<%
Option Explicit
Dim objFSO, oLogFile, myCounter
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set oLogFile = objFSO.CreateTextFile(Server.MapPath("customer_log.txt"))
oLogFile.WriteLine "BEGIN - " & Now()
'here comes your own code
'.....
'for example loop over some recordset
oLogFile.WriteLine "LOOP START - " & Now()
myCounter = 0
Do Until oRS.EOF
oLogFile.WriteLine "Loop iteration #" & (myCounter + 1) & " Started - " & Now()
'.....
'.....
'.....
oLogFile.WriteLine "Loop iteration #" & (myCounter + 1) & " Finished - " & Now()
myCounter = myCounter + 1
oRS.MoveNext
Loop
oLogFile.WriteLine "LOOP END - " & Now()
oRS.Close
oLogFile.WriteLine "Recordset was closed - " & Now()
'.....
'after your code is finished:
oLogFile.WriteLine "END - " & Now()
oLogFile.Close
Set oLogFile = Nothing
Set objFSO = Nothing
%>
Now after executing the page in a browser look for a file called "customer_log.txt" in the same directory as your ASP file and check its contents.

Resources