<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TechBlog &#187; WshShell</title>
	<atom:link href="http://techblog.byllemos.com/tag/wshshell/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.byllemos.com</link>
	<description>Accelerating into the Future with Wisdom about Technology! Ingrid Byllemos</description>
	<lastBuildDate>Tue, 05 Jan 2010 00:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Execution of batch jobs and other programs from Navision</title>
		<link>http://techblog.byllemos.com/2008/04/execution-of-batch-jobs-and-other-programs-from-navision/</link>
		<comments>http://techblog.byllemos.com/2008/04/execution-of-batch-jobs-and-other-programs-from-navision/#comments</comments>
		<pubDate>Wed, 23 Apr 2008 20:55:41 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[Run]]></category>
		<category><![CDATA[WshShell]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=63</guid>
		<description><![CDATA[<p>There are at least 2 ways of execution of external batch jobs and programs.<br />
One way is to use the SHELL command another way is to use WshShell.</p>
<p>Lets start with looking at SHELL.<br />
<span id="more-63"></span><br />
SHELL is&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>There are at least 2 ways of execution of external batch jobs and programs.<br />
One way is to use the SHELL command another way is to use WshShell.</p>
<p>Lets start with looking at SHELL.<br />
<span id="more-63"></span><br />
SHELL is a command that you can use directly in the C/AL code. It returns a &#8220;returncode&#8221; and takes name and &#8220;parameters&#8221; as parameter.</p>
<blockquote><p>ReturnCode := SHELL(&#8216;cmd.exe&#8217;,'/c&#8217;,'c:\mybatch.cmd&#8217;);</p>
<p>Where /c means execute my command and the close window (terminate).<br />
You can also use /k which will leave the execution window open.</p></blockquote>
<p>Be aware of, if you are using SHELL in Navision 4 (or higher) you will get a security message from Navision.</p>
<blockquote><p>You are about to run the following executable for the first time<br />
Executable: cmd.exe<br />
Parameter: /c mybatch.cmd</p>
<p>Please be aware that you may be running an executable that could potentially<br />
harm your computer</p>
<p>Do you trust this executable and its parameter?</p></blockquote>
<p>This message is ok in the situations where a user manually can accept the execution &#8211; but if you are running batchs jobs from a scheduler, this is not the ideal situation. Therefor in these cases I would recommend the use of WshShell &#8211; or you could always use WshShell, in that way you would never be shown the security warning <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>So how do we use WshShell? WshShell is an automation, which I have earlier mentioned in the articles about <a title="SendKeys" href="http://techblog.byllemos.com/?p=6" target="_blank">SendKeys</a>. You can execute a batch job by using the command Run.</p>
<blockquote><p>IF ISCLEAR(WshShell) THEN<br />
<blankspace>&#8230;.</blankspace>CREATE(WshShell);</p>
<p>WshMode := 1;<br />
WaitForEndOfCommand := TRUE;</p>
<p>ReturnCode := WshShell.Run(&#8216;cmd.exe /c c:\mybatch.cmd&#8217;,<br />
<blankspace>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</blankspace>WshMode,<br />
<blankspace>&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</blankspace>WaitForEndOfCommand);</p>
<p>WshShell is defined as &#8216;Windows Script Host Object Model&#8217;.WshShell<br />
WshMode is an integer and is used to handle the Window Style (minimized, maximize etc.). Valid values can be found <a title="Windows Script Host - Run Method" href="http://msdn2.microsoft.com/en-us/library/d5fk67ky(VS.85).aspx" target="_blank">here.</a></p></blockquote>
<p>WshShell requires a few more lines of codes than SHELL &#8211; but I think its worth the effort.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/04/execution-of-batch-jobs-and-other-programs-from-navision/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Sendkeys in Visual Basic Scripts</title>
		<link>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/</link>
		<comments>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/#comments</comments>
		<pubDate>Wed, 27 Feb 2008 21:56:48 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Scripts]]></category>
		<category><![CDATA[Basic]]></category>
		<category><![CDATA[Sendkeys]]></category>
		<category><![CDATA[vbs]]></category>
		<category><![CDATA[WshShell]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=43</guid>
		<description><![CDATA[<p>Sendkeys can also be used from a Visual Basic Scripts, which means you can ex. build a vbs file, that can be used for starting up applications, or executing steps that you often have to do.</p>
<p>This is an example&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>Sendkeys can also be used from a Visual Basic Scripts, which means you can ex. build a vbs file, that can be used for starting up applications, or executing steps that you often have to do.</p>
<p>This is an example on starting the Notepad and afterwards, as the first thing to do writing the word Hallo:<span id="more-43"></span></p>
<blockquote><p> set WshShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)<br />
WshShell.Run &#8220;notepad&#8221;</p>
<p>WScript.Sleep 100</p>
<p>WshShell.AppActivate &#8220;Notesblok&#8221;<br />
WshShell.SendKeys &#8220;Hallo&#8221;</p>
<p>Set WshShell = nothing</p></blockquote>
<p>Lets take a closer look on what the script actual do. The first step is to initiate the object:</p>
<p>set WshShell = WScript.CreateObject(&#8220;WScript.Shell&#8221;)</p>
<p>when the object is initiate, the Notepad application is being startet:</p>
<blockquote><p>WshShell.Run &#8220;notepad&#8221;</p></blockquote>
<p>To be sure that notepad is up and running, there has to be a kind of wait state before continuing. This is done be telling the script to Sleep x milliseconds:</p>
<blockquote><p>WScript.Sleep 100</p></blockquote>
<p>Now the Notepad application has to be activated:</p>
<blockquote><p>WshShell.AppActivate &#8220;Notesblok&#8221;</p></blockquote>
<p>Once Notepad has been activated, it is ready to receive keys. Which now can be send with the sendkeys command:</p>
<blockquote><p>WshShell.SendKeys &#8220;Hallo&#8221;</p></blockquote>
<p>Finally you have to clean up after you &#8211; which means, to stop / close the WshShell you have to set it to nothing.</p>
<blockquote><p>Set WshShell = nothing</p></blockquote>
<p>Thats it &#8211; now you have written the Visual Basic Script &#8211; and all you have to do is save it as a vbs file, or incorporate it into a web page using th vbscript tags.</p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/02/sendkeys-in-visual-basic-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sendkeys in Navision</title>
		<link>http://techblog.byllemos.com/2008/01/sendkeys-in-navision/</link>
		<comments>http://techblog.byllemos.com/2008/01/sendkeys-in-navision/#comments</comments>
		<pubDate>Tue, 22 Jan 2008 22:45:50 +0000</pubDate>
		<dc:creator>iby</dc:creator>
				<category><![CDATA[Automations]]></category>
		<category><![CDATA[Navision]]></category>
		<category><![CDATA[Sendkeys]]></category>
		<category><![CDATA[Windows Script Host Object Model]]></category>
		<category><![CDATA[WshShell]]></category>

		<guid isPermaLink="false">http://techblog.byllemos.com/?p=6</guid>
		<description><![CDATA[<p>With SendKeys you simulate user keystrokes &#8211; which mean it is possible to start applications, enter information, choose menus, buttons etc.</p>
<p>SendKeys is a part of Windows Script Host.</p>
<p>Currently I am using this functionality to take over a second&#8230;</p>]]></description>
			<content:encoded><![CDATA[<p>With SendKeys you simulate user keystrokes &#8211; which mean it is possible to start applications, enter information, choose menus, buttons etc.</p>
<p>SendKeys is a part of Windows Script Host.</p>
<p>Currently I am using this functionality to take over a second Navision Client, to start an export of objects without any user interventions.</p>
<p><span id="more-6"></span></p>
<p>In Navision SendKeys are found in the automation <em>Windows Script Host Object Model</em> class <em>WshShell</em>.</p>
<p>The first thing to do is to create the automation:</p>
<blockquote><p>IF ISCLEAR(WshShell) THEN<br />
<blankspace>&#8230;..</blankspace>CREATE(WshShell);</p></blockquote>
<p>Activate the application which has to behandled:</p>
<blockquote><p>WshShell.AppActivate(AppName);</p></blockquote>
<p>And then send the keys:</p>
<blockquote><p>WaitForKeys := TRUE;</p>
<p>WshShell.SendKeys(&#8216;{ESC 2}&#8217;,WaitForKeys);<br />
WshShell.SendKeys(&#8216;{DOWN}&#8217;,WaitForKeys);<br />
WshShell.SendKeys(&#8216;{LEFT}&#8217;,WaitForKeys);<br />
WshShell.SendKeys(&#8216;Ver{ENTER}&#8217;,WaitForKeys);</p></blockquote>
<p>When you are finished sending keys then stop the automation by clearing it:</p>
<blockquote><p>CLEAR(WshShell);</p></blockquote>
<p>Pretty simple – right <img src='http://techblog.byllemos.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://techblog.byllemos.com/2008/01/sendkeys-in-navision/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

