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

VBS Logon Script - Welcome Message

Status
Not open for further replies.

Rubymoon

IS-IT--Management
Jul 7, 2008
13
CA
Hello everyone, first time poster here.

Ok, after looking for hours, I decided to seek help from the masters. I am not extremely familiar with VB Script but i get around.

What I would like to do is create a logon script and display a welcome message. So far I don't have a problem doing a simple one. What I would like to do, is that the script would execute a .txt file on the server to display a customisable message that someone in the office can change once in a while.

So basicallaly, i'd like to know how can a vbs script display a welcome message stored into a .txt file.

Thank you very much for the help in advance.
Thank you for your time, it is most appreciated.
- Tomiko
 
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("<file path>", 1)
Do Until objFile.AtEndOfStream
    strCharacters = objFile.ReadAll
    
Loop
Wscript.Echo strCharacters
 
or

Set objFSO = CreateObject("Scripting.FileSystemObject")
strText = objFSO.OpenTextFile("file path", 1).ReadAll

However, if you intend on allowing someone to modify the file you may want to add additional error handling.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I'd take this a different route and use IE to display the message. That way you can format it a bit. Be sure you edit the UNC path to the text file.

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("[red]\\server\share\Test.txt[/red]") Then
	strText = objFSO.OpenTextFile("[red]\\server\share\Test.txt[/red]", 1).ReadAll
	Set objIE = CreateObject("InternetExplorer.Application")
	objIE.navigate2 "about:blank" : objIE.width = 350 : objIE.height = 480 : objIE.toolbar = false : objIE.menubar = false : objIE.statusbar = false : objIE.visible = True
	objIE.document.write "<font color=blue>"
	objIE.document.write "<h1>Important Announcement</h1>"
	objIE.document.write strText
	objIE.document.write "</font>"
End If


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Hello everyone, I thank you very much for your answers. I've messed with a lot of them, I'm getting better at VBscript everyday ^^;

I actually really liked the idea of iexplore displaying the message, I messed with it some but I cannot get it to work, the best part about it is that I can manipulate the text and it looks cleaner, which was part of my problem.

Here is my full code, I suppose it should display the file but it doesn't, I dont see the message in the file, and I get an error message for closing IE.

__________________________________________________________


On Error Resume Next

Dim objFSO,objIE

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("E:\Scripts\Final\wmessage.txt") Then
strText = objFSO.OpenTextFile("E:\Scripts\Final\wmessage.txt", 1).ReadAll
Set objIE = CreateObject("InternetExplorer.Application")
objIE.navigate2 "about:blank" : objIE.width = 350 : objIE.height = 480 : objIE.toolbar = false : objIE.menubar = false : objIE.statusbar = false : objIE.visible = True
objIE.document.write "<font color=blue>"
objIE.document.write "<h1>Important Announcement</h1>"
objIE.document.write strText
objIE.document.write "</font>"
End If

wscript.quit

___________________________________________________________

I would really appreciate if someone could tell me what im doing wrong with this, so I could implement this soon, Thank you very much and Have a Nice Day!
 
You need to use a UNC path as I specified. When a client logging in executes the script, it will be looking for the source file to exist in the path specified. So unless you are pushing the text file out to every workstation in the same path, then it won't work. Put the text file in a share on the server.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
this works

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
strText = objFSO.OpenTextFile("C:\Scripts\message.txt", 1).ReadAll

Set objExplorer = CreateObject _
    ("InternetExplorer.Application")

objExplorer.Navigate "about:blank"   
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Fullscreen = 1
objExplorer.Left =  0
objExplorer.Top =   0
objExplorer.Visible = 1             
objExplorer.Document.Body.Style.Cursor = "wait"
Set objDocument = objExplorer.Document	
	objDocument.Open
	objDocument.Writeln "<Body BGColor=#FFFFFF SCROLL=NO>"	
	objDocument.Writeln "</BODY>"  
	 objDocument.Writeln strText
	 objDocument.Close
	 wscript.sleep 10000
	 objExplorer.Quit
 
What it displays is always written "Undefined" even when I changed to UNC path, the E: was only for the test.

Thank You very much
 
Remove your Option Explicit or define the new variables.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Ok, I think i gave myself too much credit, lol ^^;

I've been messing around with the code, and I haven't been able to solve my problem with it, would it be possible for someone to give me a full code from start to bottom with a dummy path to display in IE, I'm obviously not able to define the variables.

Got myself a book on VBScript, still learning ^^;

Thank you very much
Sorry for the inconvenience >.<
 
Ok, i'm sorry, I just figured it out. Only one question tho, would it be possible to Center the text or change font size?

Thank You
 
It is html code so you can do whatever you want with it that html supports.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Rubymoon:

How did you make your Welcome Message to work? I'm having the same problem you had and I don't see the script you used to solve your problem. Could you please post the (code) script for me.
I'm only getting a blank IE window without a welcome message on the side of the screen. Were you able to center your message?

Thanks for your help!
 
Sorry for the late answer, something about working my butt off for the last month :p

My final script looks like this

P.S. I'm not a scripting guru, but eh, it works well for what I do with it. It also displays an animated gif at the top. I wish I could do a JPG, but it never displays for some reason, and ... im a n00b :p

Have a nice day

_____________________________________________________________

On Error Resume Next

Set objFSO = CreateObject("Scripting.FileSystemObject")
strText = objFSO.OpenTextFile("\\server\logon$\wmessage.txt", 1).ReadAll

Set objExplorer = CreateObject ("InternetExplorer.Application")

objExplorer.Navigate "about:blank"
objExplorer.ToolBar = 0
objExplorer.StatusBar = 0
objExplorer.Fullscreen = 0
objExplorer.Left = 1
objExplorer.Top = 50
objExplorer.Width = 360
objExplorer.Height = 470
objExplorer.Visible = 1
objExplorer.Document.Body.Style.Cursor = "wait"
objExplorer.Document.Title = "Logon Script In Progress"
objExplorer.Document.Body.InnerHTML = "<img src='file:///\\server\NETLOGON\progress.gif' height=100 width=300>" & "<br><br> <br><br>" & strText & "<br><br> <br><br>" & "<br><br>The Logon Script Terminated Successfully<br><br>"

objDocument.Close
wscript.sleep 11000
objExplorer.Quit

Do While (objExplorer.Busy)
Wscript.Sleep 200
Loop

Set objFSO = NOTHING
Set objExplorer = NOTHING

wscript.quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top