{"id":158,"date":"2013-04-16T18:34:02","date_gmt":"2013-04-17T01:34:02","guid":{"rendered":"http:\/\/blog.gptnet.net\/?p=158"},"modified":"2013-04-16T18:36:35","modified_gmt":"2013-04-17T01:36:35","slug":"create-config-file-with-vb-script","status":"publish","type":"post","link":"https:\/\/blog.gptnet.net\/?p=158","title":{"rendered":"create config file with VB script"},"content":{"rendered":"<p>The following script will demonstrate how to create configuration file for an application via VB script. We are currently running it as a login script. It&#8217;s very simple but does the job 100%. It grabs environmental variables and then generates individual config file for each computer. In my example we care about hostname and system architecture.<br \/>\n<!--more--><\/p>\n<pre lang=\"VisualBasic\" line=\"1\">\r\n'Name: settings.vbs\r\n'Created by: Naz Snidanko | nsnidanko@wajax.com\r\n'Date: 11\/03\/2013\r\n'Dexcription: Script to generate AS400 profile file .ws \r\n'15\/03\/2013 - N.S. - fixed x64 -> displayed as AMD64\r\n'17\/03\/2013 - N.S. - replaced %HOMEPATH% with %USERPROFILE%\r\n\r\n'Function to parse computer name and generate Workstation ID\r\nFunction WorkstID (strHostName1, strHostBranch1)\r\nDim strHostNumb\r\n'Get Hostname number\r\nstrHostNumb = Right(strHostName1, 3)\r\n'generate Workstation ID if host number is higher than 099\r\nIf ( Left(strHostNumb, 1) = \"0\" ) Then\r\nWorkstID = \"CA\" & strHostBranch1 & Right(strHostNumb, 2)\r\n'generate Workstation ID if host number is lower than 100\r\nElse\r\nWorkstID = \"CA\" & strHostBranch1 & strHostNumb\r\nEnd If\r\nEnd Function\r\n\r\nDim wshShell, objFSO, objTextFile, sFileName, sArchitecture, sHostName, strSetting\r\nConst ForWriting = 2\r\nSet wshShell = CreateObject( \"WScript.Shell\" )\r\nsArchitecture = wshShell.ExpandEnvironmentStrings(\"%PROCESSOR_ARCHITECTURE%\")\r\nsHostName = wshShell.ExpandEnvironmentStrings(\"%COMPUTERNAME%\")\r\nSet objFSO = CreateObject(\"Scripting.FileSystemObject\")\r\nsFileName = wshShell.ExpandEnvironmentStrings(\"%USERPROFILE%\\Desktop\")\r\nsFileName = sFileName & \"\\AS400.ws\"\r\n'This is to capture if file already created. Do not execute the rest...\r\nIf objFSO.FileExists(sFileName) Then\r\nWScript.Quit\r\nElse\r\n \r\n 'Set path depending on computer architecture\r\n if (sArchitecture = \"x86\") Then\r\n strSetting = \"C:\\Program Files\\IBM\\Client Access\\Emulator\\Private\\STDAS400.\"\r\n ElseIf sArchitecture = \"AMD64\" Then\r\n strSetting = \"C:\\Program Files (x86)\\IBM\\Client Access\\Emulator\\Private\\STDAS400.\"\r\n end if\r\n  'Toronto branch code 2\r\n  If InStr(sHostName, \"TOR\") Then\r\n  strLine = WorkstID (sHostName, \"2\")\r\n  'Hamilton branch code 3\r\n  ElseIf InStr(sHostName, \"STO\") Then\r\n  strLine = WorkstID (sHostName, \"3\")\r\n  'London branch code 4\r\n  ElseIf InStr(sHostName, \"LON\") Then\r\n  strLine = WorkstID (sHostName, \"4\")\r\n  'Ottawa branch code 5\r\n  ElseIf InStr(sHostName, \"OTT\") Then\r\n  strLine = WorkstID (sHostName, \"5\")\r\n  'Niagara branch code 6\r\n  ElseIf InStr(sHostName, \"NIA\") Then \r\n  strLine = WorkstID (sHostName, \"6\")\r\n  'Sudbury branch code 7\r\n  ElseIf InStr(sHostName, \"SUD\") Then\r\n  strLine = WorkstID (sHostName, \"7\")\r\n  'Timmins branch code 8\r\n  ElseIf InStr(sHostName, \"TIM\") Then\r\n  strLine = WorkstID (sHostName, \"8\")\r\n  'Thunder Bay branch code T \r\n  ElseIf InStr(sHostName, \"THU\") Then\r\n  strLine = WorkstID (sHostName, \"T\")\r\n  Else\r\n    'catch error + CON, COR, PEM - stop script execution\r\n    WScript.Quit\r\n  End If\r\n\r\n   ' Overwrite any existing file\r\n   Set objTextFile = objFSO.OpenTextFile (sFileName, ForWriting, True)\r\n\r\n   ' Write the configuration settings\r\n   objTextFile.WriteLine(\"[Profile]\")\r\n   objTextFile.WriteLine(\"ID=WS\")\r\n   objTextFile.WriteLine(\"Version=8\")\r\n   objTextFile.WriteLine(\"[CT]\")\r\n   objTextFile.WriteLine(\"trace=Y\")\r\n   objTextFile.WriteLine(\"[Telnet5250]\")\r\n   objTextFile.WriteLine(\"HostName=WDDA400\")\r\n   objTextFile.WriteLine(\"AssociatedPrinterStartMinimized=N\")\r\n   objTextFile.WriteLine(\"AssociatedPrinterClose=N\")\r\n   objTextFile.WriteLine(\"AssociatedPrinterTimeout=0\")\r\n   objTextFile.WriteLine(\"Security=CA400\")\r\n   objTextFile.WriteLine(\"SSLClientAuthentication=Y\")\r\n   objTextFile.WriteLine(\"CertSelection=AUTOSELECT\")\r\n   objTextFile.WriteLine(\"AutoReconnect=Y\")\r\n   objTextFile.WriteLine(\"[Communication]\")\r\n   objTextFile.WriteLine(\"Link=telnet5250\")\r\n   objTextFile.WriteLine(\"Session=5250\")\r\n   objTextFile.WriteLine(\"[5250]\")\r\n   objTextFile.WriteLine(\"ScreenSize=27x132\")\r\n   objTextFile.WriteLine(\"HostCodePage=037-U\")\r\n   objTextFile.WriteLine(\"WorkStationID=\") & strLine\r\n   objTextFile.WriteLine(\"PrinterType=IBM3812\")\r\n   objTextFile.WriteLine(\"[Keyboard]\")\r\n   objTextFile.WriteLine(\"CuaKeyboard=2\")\r\n   objTextFile.WriteLine(\"Language=United-States\")\r\n   objTextFile.WriteLine(\"IBMDefaultKeyboard=N\")\r\n   objTextFile.WriteLine(\"DefaultKeyboard=\") & strSetting & (\"KMP\")\r\n   objTextFile.WriteLine(\"[Poppad]\")\r\n   objTextFile.WriteLine(\"IBMDefaultPoppad=N\")\r\n   objTextFile.WriteLine(\"DefaultPoppad=\") & strSetting & (\"PMP\")\r\n   objTextFile.WriteLine(\"[HotSpot]\")\r\n   objTextFile.WriteLine(\"Exists=Y\")\r\n   objTextFile.WriteLine(\"template1=PF PFnn\")\r\n   objTextFile.WriteLine(\"template2=PF FPnn\")\r\n   objTextFile.WriteLine(\"template3=PF Fnn\")\r\n   objTextFile.WriteLine(\"template4=PF nn\")\r\n   objTextFile.WriteLine(\"template5=URL\")\r\n   objTextFile.WriteLine(\"template6=cursor\")\r\n   objTextFile.WriteLine(\"[Colors]\")\r\n   objTextFile.WriteLine(\"OtherColumnSeparator=000000\")\r\n   objTextFile.WriteLine(\"[Window]\")\r\n   objTextFile.WriteLine(\"SessFlags=38C63\")\r\n   objTextFile.WriteLine(\"ViewFlags=CE00\")\r\n   objTextFile.WriteLine(\"RuleLinePos=0 0\")\r\n   objTextFile.WriteLine(\"[LastExitView]\")\r\n   objTextFile.WriteLine(\"A=3 150 150 853 682 3 11 20 400 0 IBM3270\u2014 37\")\r\n   objTextFile.WriteLine(\"[printers]\")\r\n   objTextFile.WriteLine(\"printer=DEFAULT\")\r\n   objTextFile.WriteLine(\"Drawer1Orient=Portrait\")\r\n   objTextFile.WriteLine(\"Drawer2Orient=Portrait\")\r\n   objTextFile.WriteLine(\"VTPrintArea=Scroll\")\r\n   objTextFile.WriteLine(\"VTPrintChar=ASCII\")\r\n   objTextFile.WriteLine(\"VTTerminator=None\")\r\n   objTextFile.Close\r\nEnd If\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following script will demonstrate how to create configuration file for an application via VB script. We are currently running it as a login script. It&#8217;s very simple but does the job 100%. It grabs environmental variables and then generates &hellip; <a href=\"https:\/\/blog.gptnet.net\/?p=158\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-random-stuff"],"_links":{"self":[{"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":2,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"predecessor-version":[{"id":160,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions\/160"}],"wp:attachment":[{"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gptnet.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}