Running "net user "user" /domain" command and read results in classic asp - cmd

First of all sorry for poor english.
I am using Classic ASP for simple things on my network. I want users to view their domain password expire date on our intranet page. Intranet page runs classic asp.
on CMD or powershell
"net user "username" /domain"
command gives the result. On asp page I need to run this command and read the result of password expire date.
Can you pls help me.
Thanks.

If you redirect output into a text file, you can read the file from asp:
Set w = Server.CreateObject("WScript.Shell")
w.Run "cmd /c net user > c:\temp\output.txt", 0, true ' send output into file
Set s = CreateObject("Scripting.FileSystemObject")
Set f = s.OpenTextFile("c:\temp\output.txt", 1) ' read file
o = f.ReadAll
f.Close
response.write o
Of course, this will require access of asp account to execute given command and
read/write access to the file.

Related

compiling less to css from classic asp / vbscript

I'm trying to get classic asp / vbscript to run a less compiler (https://github.com/duncansmart/less.js-windows). Running the exact command from a real cmd prompt on the server works fine. So it's going to be one of those permissiony type things. My server is Win2003 x86 / IIS6.
<%
' foo.asp
outpath = "c:\inetpub\wwwroot\site\less"
cmd = "c:\less.js-windows-v1.6.2\lessc.cmd"
Set Shell = server.createobject("WScript.Shell")
nodeCommand = cmd & " " & outPath & "\app.less " & outPath & "\app.css"
errCode = Shell.Run(nodeCommand, 0, True)
' errcode = 1
%>
foo.asp is running somewhere on the web server, anonymously.
cmd.exe has had iusr_server added so that it has read and execute permission.
c:\less.js-windows-v1.6.2 has had iusr_server added with read/execute as well.
I've granted everyone permission to modify files in side c:\inetpub\wwwroot\site\less to make sure it's not a permission thing.
I have tried modifying my command to include CMD /C ahead of the command file name.
Use the following process:
Stop the server
Change relative paths to full paths for all files
Reconfigure the IUSR to be you
Restart the server

VBScript (HTA) MapNetworkDrive - Logon Failure

I am trying to create a HTA file that, among other things, connects to a remote network drive on a Windows 7 PC. In order to do this I need a username / password. I have the following code:
Sub ConnectDrive
Set objNetwork = CreateObject("WScript.Network")
Set oShell = CreateObject("Shell.Application")
objNetwork.MapNetworkDrive "x:", "\\testsystem3\temp", False, User, Pass
If Err.Number = 0 Then
oShell.NameSpace("x:").Self.Name = "Temp on TS3"
End If
Set oShell = Nothing
Set objNetwork = Nothing
End Sub
User and Pass are the actual username and password used in order to connect.
The problem is that I get a Logon failure error message: "Logon failure: unknown user name or bad password".
I am sure that the username and password are ok since using the net use x: \\testsystem3\temp /user:User pass command connects the drive successfully.
Any suggestions how to get this to work? I could turn off password protected sharing on the Windows 7 machine but I wouldn't like that...
Thank you!

Running IIS Express "silent", ie without HTTP console output?

I'm testing the responsiveness of a web application, and want to isolate any slow areas (database access, javascript, etc) and want to be sure that IIS Express isn't slowing things down by all its console output.
Is there a way of running IIS Express without that output, or even without the console being visible at all?
I've tried the /trace:error option, but it still outputs lines for every request.
the following should do the trick:
Create a VBScript: IIS-Express-silent.vbs
Dim App,Site
Site = "[YOUR SITE NAME]"
If Len(Site) < 1 Then
Site = WScript.Arguments(0)
End If
App = """%PROGRAMFILES%\IIS Express\iisexpress""" & _
" /site:" & Site
If Len(Site) > 0 Then
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run App, 0
Set WshShell = Nothing
End If
If you are running IIS Express only as localhost and you don't (intend to) use SSL then you are ready. Just add [YOUR SITE NAME] from applicationhost.config located in your user profile:
<sites>
<site name="[YOUR SITE NAME]" id="1" serverAutoStart="true">
...
</sites>
If you need elevated privileges you must create a second file in the same directory (VBScripts can't be run this way directly): Run-as-Administrator.bat
#echo off
pushd %~dp0
cscript IIS-Express-silent.vbs [YOUR SITE NAME]
Please leave Site in your VBScript blank then and add the name in your batch file instead.
Right mouse button - "Run as Administrator" - and you're done :-)

How to change my DC password

I'm logged in with my Windows 7 to the domain.
I want to programmaticaly change my user's password.
I tried to do "net user /domain" But i've got Access denied error.
I don't want to change it manually (CTRL+ALT+DELETE, change password ...).
I'll be happy to get an answer in command line, python, c++ or c#.
Thanks,
Mattan
Not sure how to include it in C#, but there is Netapi32.dll library that incorporates the NetUserChangePassword function. http://msdn.microsoft.com/en-us/library/windows/desktop/aa370650%28v=vs.85%29.aspx
In python, there are two easy ways to do it. With ctypes you can include it by typing:
from ctypes.wintypes import windll
ChangePassword = windll.Netapi32.NetUserChangePassword
Then change the password by typing:
ChangePassword(domainname, username, oldpass, newpass)
"domainname" could be zero if you want to assign the password on current logon domain.
However, if you already have windows tools for python istalled, then you could use win32net to change the password:
import win32net
win32net.NetUserChangePassword(domainname, username, oldpass, newpass)
Again, 0 can be used instead of domain name.
You can use the simple VB script (named changepass.vbs):
Dim UserDomain
Dim UserName
Dim NewPassword
UserDomain = WScript.Arguments.Item(0)
UserName = WScript.Arguments.Item(1)
NewPassword = WScript.Arguments.Item(2)
Set User = GetObject("WinNT://"& UserDomain &"/"& UserName & "")
Call User.SetPassword(NewPassword)
If err.number = 0 Then
Wscript.Echo "The password change was successful."
Else
Wscript.Echo "The password change failed!"
End if
It accepts 3 parameters: domain name, user name and a new password. The current user must have permissions to change the password. If you want to change password on the local computer provide "." as a domain name. Example:
cscript changepass.vbs "YOUR_DOMAIN" "user1" "qw23442q"

Reset password for renamed Administrator account

I need to create a .VBS script to reset the Windows local administrator password on a large group of computers. My problem is that some of our sites have renamed the administrator account for security reasons. Does anyone have a script which changes the password of the administrator account based on the SID of the original Administrator account?
Using the fact that local admin's SID always ends with -500:
strComputer="." ' local computer by default
Set objUser=GetObject("WinNT://" & strComputer & "/" & GetAdminName & ",user")
objUser.SetPassword "New local admin password"
objUser.SetInfo
Function GetAdminName
'This function was written using information from Table J.1 from the Windows XP resource Kit
'http://www.microsoft.com/resources/documentation/Windows/XP/all/reskit/en-us/Default.asp?url=/resources/documentation/Windows/XP/all/reskit/en-us/prnc_sid_cids.asp
Set objNetwork = CreateObject("Wscript.Network") 'get the current computer name
objComputerName = objNetwork.ComputerName
Set objwmi = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & objComputerName)
qry = "SELECT * FROM Win32_Account where Domain = '" & cstr(objComputerName) & "'"
'set query, making sure to only look at local computer
For Each Admin in objwmi.ExecQuery(qry)
if (left(admin.sid, 6) = "S-1-5-" and right(admin.sid,4) = "-500") then 'look for admin sid
GetAdminName = admin.name
end if
next
end Function
There's a tool floating around somewhere called LookupAccountName (with source!) that given the SID of the builtin adminitrator will give you its name.
You're probably going to end up writing C++ code to pull this one off reasonably well.
Like Joshua says, I don't think you can do this with windows scripting host only, you could use it download something and execute it:
A custom app that calls LookupAccountSid(S-1-5-domain-500 SID or enum admin group)+NetUserSetInfo to reset the password (Needs to run this as admin)
http://home.eunet.no/pnordahl/ntpasswd/ (Reset at boot)
Dump the SAM hashes and crack the password (Cain,John the Ripper,L0phtCrack etc)
#DmitryK's answer is good, and I didn't know any of that stuff. But I do know that this sort of thing is usually cleaner in PowerShell, so I ported it.
For example, the whole GetAdminName function can be written:
$adminName = (gwmi win32_account | ? { $.SID.StartsWith( 'S-1-5-' ) -and $.SID.EndsWith( '-500' ) }).Name
(Add the -ComputerName option to the gwmi call to do this on a server.)
The rest becomes:
$user = ([ADSI]"WinNT://$($env:COMPUTERNAME)/$adminName,User")
$user.SetPassword( 'xxx' )
$user.SetInfo()
(applying the appropriate computer name as needed, of course.)

Resources