Petri IT Knowledgebase Forums
 

Petri.co.il forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.co.il is happy to award auglan the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read

Notices

Sharing: Determine TS dynamic client printer name for static application mapping.

Sharing: Determine TS dynamic client printer name for static application mapping.

this thread has 0 replies and has been viewed 2171 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 24th April 2007, 21:00
ahinson's Avatar
ahinson ahinson is offline
Moderator
 
 Join Date: Mar 2004
  6 month star 12 month star
 Location: Orlando, FL
 Posts: 1,821
 Reputation: ahinson is just really niceahinson is just really niceahinson is just really niceahinson is just really niceahinson is just really nice (440)
Default Sharing: Determine TS dynamic client printer name for static application mapping.

We use a label printer in our application that is statically mapped within. This is done for speed so that users aren't prompted each time a job is sent. Because terminal server dynamically adds the session id to the end of the printer name it caused a problem. This solution uses a logon script with a batch file and VBscript.

We assign the static portion of the printer name in the config file for the app and append the dynamic portion of the name via the script.

Batch file:
Code:
qwinsta > "%UserProfile%\getsession.txt"
call getsession.vbs
QWINSTA returns the following:
Code:
 SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 console           administrator             0  Active  wdcon
 rdp-tcp                                 65536  Listen  rdpwd
>rdp-tcp#70        administrator             3  Active  rdpwd
                   kcc                       2  Disc    rdpwd
VBscript:
Code:
option explicit
on error resume next

dim objFSO, objShell, file1, file2, file3, strSpath, strPath, strFolder, strLine

Set objShell = CreateObject("WScript.Shell")

strSpath = objShell.ExpandEnvironmentStrings("%UserProfile%") & "\GetSession.txt"
strPath = "L:\APPS\LAB\blah.ini" 'This file must exist
strFolder = "L:\APPS\LAB\tmp.txt"

Main 

Sub Main()
  
Copy()

  if not file1 is nothing then set file1 = nothing
  if not file2 is nothing then set file2 = nothing
  if not file3 is nothing then set file3 = nothing
  if not objFSO is nothing then set objFSO = nothing
End Sub

Sub Copy()
set objFSO = CreateObject("Scripting.FileSystemObject")

  if err.number <> 0 then 
    exit sub 
  end if

  if not objFSO.FileExists(strPath) then 
    exit sub
  end if

  if objFSO.FileExists(strFolder) then
    objFSO.DeleteFile(strFolder) 
  end if

set file1 = objFSO.OpenTextFile(strPath)
  if err.number <> 0 then 	
    exit sub
  end if
	
set file2 = objFSO.CreateTextFile(strFolder) 
  if err.number <> 0 then 	
    exit sub
  end if

  Do while not file1.AtEndofStream
    strLine = file1.ReadLine
      
      select Case Mid(strLine,1,8)
        case "LBLPATH2"
	  file2.WriteLine "LBLPATH2='\\TS-SERVER-1\LABEL (from BCL) in session " & GetSession(strSPath) & "'"
	case else
	  file2.WriteLine strLine
      end select
  loop
	
  if err.number <> 0 then 
    file1.close
    file2.close
    exit sub
  end if
	
  file1.close
  set file1 = nothing
  file2.close
  set file2 = nothing
	
  objFSO.DeleteFile strPath, true
	
  objFSO.MoveFile strFolder, strPath 
End Sub

Function GetSession(SessionPath)

  set objFSO = CreateObject("Scripting.FileSystemObject")
  set file3 = objFSO.OpenTextFile(SessionPath) 
        Do while not file3.AtEndofStream 
		
          strLine = file3.ReadLine
		
            select Case Mid(strLine,1,1)
	      case ">"
		GetSession = Trim(Mid(strLine,42,5))
	    end select
	loop
		
  file3.close
  set file3 = nothing
End Function
__________________
Andrew Hinson
http://www.clinlabinc.com

** Remember to give credit where credit is due and leave reputation points where appropriate **

Last edited by ahinson; 24th April 2007 at 22:50..
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Program/Application sharing, XP Home Hayem Windows 2000 Pro, XP Pro 4 30th January 2007 01:41
Application sharing using Terminal server ahmer_sahab Terminal Services 4 28th December 2006 16:41
Sharing a printer?! lirank Windows Server 2000 / 2003 4 12th September 2006 23:30
Print Server and client login script mapping chattdaddy69 Active Directory 1 9th March 2005 01:20
Printer.mapping.based.on.computer.group. azmantek General Scripting 1 24th September 2004 15:07


All times are GMT +3. The time now is 09:05.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri