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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get reports in AD from a VBS yes/no script 1

Status
Not open for further replies.

izhaar5464

Technical User
Aug 27, 2015
7
SA
Hello,

I need a VBS / HTA script to get a dialog box showing Yes/No options before logging into the system.

Users who select Yes should get their names reflected in a report and Users who select no should also get their names reflected in another report... These reports should be generated in Active Directory.
 
x=msgbox ("Have you completed the tasks" ,4, "Press yes/no")
 
The users who give yes and no should get their names reflected in AD report... I m not a techie guy.. I need some scripts and procedure to proceed.. Please help me in this issue.

I have added this script in Group policy in logon script.. And i m getting the desired output... Just need to fetch the reports of the users who gave yes and no separately..
 
And where is your problem ?
How to get the UserName or in the program logic ?
 
My problem is that i want to generate a report in AD... The report should have the user names who entered yes... and who entered no... How to do?
 
I thought that you want to write reports into ordinary text files.
Don't know, how to generate reports in AD.
 
Its ok if i write reports in ordinary files also.... Can u help me in that issue? Is there any scripting line that i can add to copy the output in another file
 
I thought, that it might look something like this:

report.vbs
Code:
[COLOR=#0000ff]' retrieve username from system variable[/color]
usrname [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color] [COLOR=#ff00ff]"WScript.Shell"[/color][COLOR=#804040][b]).[/b][/color]ExpandEnvironmentStrings[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"%USERNAME%"[/color][COLOR=#804040][b])[/b][/color]
[COLOR=#0000ff]' retrieve username from network[/color]
[COLOR=#0000ff]'usrname = CreateObject("WScript.Network").UserName[/color]

result[COLOR=#804040][b]=[/b][/color][COLOR=#008080]msgbox[/color] [COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Have you completed the tasks"[/color] [COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]vbYesNoCancel[/color][COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]"Press yes/no"[/color][COLOR=#804040][b])[/b][/color]
[COLOR=#804040][b]select[/b][/color] [COLOR=#804040][b]case[/b][/color] result
  [COLOR=#804040][b]case[/b][/color] [COLOR=#ff00ff]vbYes[/color]
   [COLOR=#0000ff] 'WScript.echo "You pressed YES"[/color]
    [COLOR=#804040][b]call[/b][/color] write_report[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"report_YES.txt"[/color][COLOR=#804040][b],[/b][/color] usrname[COLOR=#804040][b])[/b][/color]
  [COLOR=#804040][b]case[/b][/color] [COLOR=#ff00ff]vbNo[/color]
   [COLOR=#0000ff] 'WScript.echo "You pressed NO"[/color]
    [COLOR=#804040][b]call[/b][/color] write_report[COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"report_NO.txt"[/color][COLOR=#804040][b],[/b][/color] usrname[COLOR=#804040][b])[/b][/color]
  [COLOR=#804040][b]case[/b][/color] [COLOR=#ff00ff]vbCancel[/color]
   [COLOR=#0000ff] ' Do nothing[/color]
   [COLOR=#0000ff] 'WScript.echo "You pressed CANCEL"[/color]
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]select[/b][/color]

[COLOR=#804040][b]sub[/b][/color] write_report[COLOR=#804040][b]([/b][/color]reportname[COLOR=#804040][b],[/b][/color] username[COLOR=#804040][b])[/b][/color]
 [COLOR=#0000ff] 'WScript.echo "Writing username='" & username & _[/color]
 [COLOR=#0000ff] '             "' into report ='" & reportname & "'"[/color]
  [COLOR=#804040][b]set[/b][/color] fso [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]CreateObject[/color][COLOR=#804040][b]([/b][/color][COLOR=#ff00ff]"Scripting.FileSystemObject"[/color][COLOR=#804040][b])[/b][/color]
  [COLOR=#804040][b]const[/b][/color] ForReading [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]1[/color][COLOR=#804040][b],[/b][/color] ForWriting [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]2[/color][COLOR=#804040][b],[/b][/color] ForAppending [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]8[/color]
 [COLOR=#0000ff] ' open Report file[/color]
  [COLOR=#804040][b]set[/b][/color] report_file [COLOR=#804040][b]=[/b][/color] fso[COLOR=#804040][b].[/b][/color]OpenTextFile[COLOR=#804040][b]([/b][/color]reportname[COLOR=#804040][b],[/b][/color] ForAppending[COLOR=#804040][b],[/b][/color] [COLOR=#ff00ff]True[/color][COLOR=#804040][b])[/b][/color]
 [COLOR=#0000ff] ' line for writing into report[/color]
  report_line [COLOR=#804040][b]=[/b][/color] username
  report_file[COLOR=#804040][b].[/b][/color][COLOR=#a020f0]writeline[/color][COLOR=#804040][b]([/b][/color]report_line[COLOR=#804040][b])[/b][/color]
 [COLOR=#0000ff] ' close Report file[/color]
  report_file[COLOR=#804040][b].[/b][/color][COLOR=#804040][b]Close[/b][/color]              
[COLOR=#804040][b]end[/b][/color] [COLOR=#804040][b]sub[/b][/color]

If you want the user name from network then uncomment the appropriate line.
Or if you want to see how the program works uncomment the lines with WScript.echo ...
Change the path of files where they should be created
 
1 small help... How to add date section in the script... Coz i need the username with the logon date
 
quickly: to insert current date and time you can use
Code:
...
[highlight]  ' get current date and time
  date_time = now
  ' line for writing into report
  report_line = username & " - " & date_time[/highlight]
  report_file.writeline(report_line)
...
Unfortunately I do not know by heart how to determine logon date. It's not so simple - please Google for it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top